Nitpick my Perl6 - parametric roles
Anyone care to pick holes in this little expression of some Perl 6 core types as collections? I mean, other than missing methods ;) role Collection[\$types] { has Seq[$types] @.members; } role Set[::T = Item] does Collection[T] where { all(.members) =:= one(.members); }; role Pair[::K = Item, ::V = Item] does Seq[K,V] { method key of K { .[0] } method value of V { .[1] } }; role Mapping[::K = Item, ::V = Item] does Collection[Pair[K,V]] { all(.members).does(Pair) and all(.members).key =:= one(.members).key; } role Hash[Str ::K, ::V = Item] does Mapping[K, V] where { all(.members).key == one(.members).key } { method post_circumfix:<{ }> (K $key) of V|Undefined { my $seq = first { .key == $key } &.members; $seq ?? $seq.value :: undef; } } role ArrayItem[::V = Item] does Seq[Int, V] { method index of Int { .[0] } method value of Item { .[1] } }; role Array of Collection[ArrayItem] where { all(.members).index == one(.members).index } { method post_circumfix:<[ ]> (Int $index) of Item { my $seq = first { .index == $index } &.members; $seq ?? $seq.value :: undef; } } I'll take the feedback I get, and try to make a set of Perl 6 classes in the pugs project that look and feel just like regular Perl 6 hash/arrays but are expressed in more elementary particles. Cheers, Sam.
Re: postgres interface
Am Montag, 25. September 2006 00:01 schrieb Bob Rogers: > It turns out that if libpq.so doesn't exist, pg.t makes t/harness give > up completely: Yep. > I managed to get it to fail less hard (see patch): Thanks, applied. > But, as you can see, the continuation barrier gets in the way of the > error handling. Exceptions shouldn't be a problem as long as the handler doesn't try to resume execution in a different run loop. leo
Re: [TODO] fill Parrot_register_move() with code : new implementation
Am Montag, 25. September 2006 00:06 schrieb Karl Forner: > On 9/15/06, Leopold Toetsch <[EMAIL PROTECTED]> wrote: > > - There are 2 use cases for register_move > > a) optimized recursive tail calls > > b) simple function call argument passing compiled to native code in JIT > > core > So in that case ( a or b ?), the src_regs are always (0,1,2,..,n) ? > If so I'm sure that we can use this property to optimize the code. b) isn't yet using Parrot_register_move(). Therefore it isn't given that src_regs are always register positions. > The problem is that I have no clue of JIT, registers and so on. But could > you give an example of code that would > lead to that case ? Let's forget that case. JIT code is only created for simple and matching arguments. > > Again, we have to check if any argument conversions could take place and > > then > > turn off the optimization in case. > > ok, so where would the check take place ? > I can imagine an extra argument indicating whether or not doing this extra > optimization, or two different functions/implementations, > or more infomration about the registers allowing the function to decide by > itself to do or not the optimization on a register-couple basis No. There have to be an extra check before tailcall optimization is done. When there's argument conversion, which involves P registers, Parrot_register_move() will not be used at all. > So is there anything more I could do on this subject ? Well, you could have a look at recursive_tail_call() in compilers/imcc/pcc.c and improve the checks, if the tailcall can be optimized. > Karl leo
[perl #40410] Segfault in packfile code
# New Ticket Created by Jonathan Worthington # Please include the string: [perl #40410] # in the subject line of all future correspondence about this issue. # http://rt.perl.org/rt3/Ticket/Display.html?id=40410 > Hi, Parrot segfaults while generating a packfile for a (large) chunk of compiled PIR generated by the .Net translator. You'll need a copy of Mono installed to replicate it, I'm too tired to track this down any further tonight. (gdb) r net2pbc.pbc -f -o mscorlib.pbc /usr/lib/mono/1.0/mscorlib.dll Starting program: /home/default/jnthn.net/dev/parrot/parrot net2pbc.pbc -f -o mscorlib.pbc /usr/lib/mono/1.0/mscorlib.dll Reading symbols from shared object read from target memory...done. Loaded system supplied DSO at 0x55e000 [Thread debugging using libthread_db enabled] [New Thread -1208564032 (LWP 9073)] [New Thread -1208702048 (LWP 9076)] [New Thread -1219191904 (LWP 9077)] Translated 744 types out of 1365 from /usr/lib/mono/1.0/mscorlib.dll Program received signal SIGSEGV, Segmentation fault. [Switching to Thread -1208564032 (LWP 9073)] 0x00cea077 in PF_store_string (cursor=0xb2a18bd0, s=0xb69d0788) at src/packfile/pf_items.c:565 565 *cursor++ = PObj_get_FLAGS(s); /* only constant_FLAG and private7 */ (gdb) bt #0 0x00cea077 in PF_store_string (cursor=0xb2a18bd0, s=0xb69d0788) at src/packfile/pf_items.c:565 #1 0x00cb7819 in PackFile_Constant_pack (interpreter=0x83da008, self=0xa2a8458, cursor=0xb2a18bd0) at src/packout.c:249 #2 0x00cb7669 in PackFile_ConstTable_pack (interpreter=0x83da008, seg=0x88b7c98, cursor=0xb2a18bcc) at src/packout.c:169 #3 0x00c5f328 in PackFile_Segment_pack (interpreter=0x83da008, self=0x88b7c98, cursor=0xb28ab450) at src/packfile.c:1302 #4 0x00c5fe62 in directory_pack (interpreter=0x83da008, self=0xa84b8d0, cursor=0xb28ab440) at src/packfile.c:1697 #5 0x00c5f328 in PackFile_Segment_pack (interpreter=0x83da008, self=0xa84b8d0, cursor=0xb2793ba0) at src/packfile.c:1302 #6 0x00cb753a in PackFile_pack (interpreter=0x83da008, self=0xa84b8d0, cursor=0xb2793b90) at src/packout.c:105 #7 0x00d1969c in Parrot_Eval_get_string (interpreter=0x83da008, pmc=0xb65fac14) at src/pmc/eval.pmc:250 #8 0x00b778f0 in Parrot_print_p_p (cur_opcode=0xb6ae7348, interpreter=0x83da008) at src/ops/io.ops:339 #9 0x00c687eb in runops_slow_core (interpreter=0x83da008, pc=0xb6ae7348) at src/runops_cores.c:184 #10 0x00c546d8 in runops_int (interpreter=0x83da008, offset=317) at src/interpreter.c:775 #11 0x00c5932e in runops (interpreter=0x83da008, offs=3) at src/inter_run.c:87 ---Type to continue, or q to quit--- #12 0x00c59584 in runops_args (interpreter=0x83da008, sub=0x855ffd0, obj=0x841bab0, meth=0x0, sig=0xdad996 "vP", ap=0xbfc771fc "¨çZ\bØrÇ¿Ðj\032") at src/inter_run.c:193 #13 0x00c59698 in Parrot_runops_fromc_args (interpreter=0x83da008, sub=0x855ffd0, sig=0xdad996 "vP") at src/inter_run.c:287 #14 0x00cb6f5e in Parrot_runcode (interpreter=0x83da008, argc=5, argv=0xbfc77378) at src/embed.c:806 #15 0x0804afaf in main (argc=5, argv=0xbfc77378) at compilers/imcc/main.c:731 Jonathan
Parrot Bug Summary
Parrot Bug Summary http://rt.perl.org/rt3/NoAuth/parrot/Overview.html Generated at Mon Sep 25 13:15:02 2006 GMT --- * Numbers * New Issues * Overview of Open Issues * Ticket Status By Version * Requestors with most open tickets --- Numbers Ticket Counts: 89 new + 268 open = 357 Created this week: 18 Closed this week: 13 --- New Issues New issues that have not been responded to yet 1 - 2 weeks old 40347 Can't determine revision under Subversion 1.4.0 2 - 3 weeks old 40313 [TODO] Tcl - full namespace support 40312 [TODO] Tcl - support namespaces in [info commands] 3 - 4 weeks old 4 - 5 weeks old 40217 Parrot_autoload_class() knows about Python and Tcl 5 - 6 weeks old 40191 [PATCH] PGE simple grammar test file revisited 40182 [TODO] Convert PGE::CodeString to .pmc 40156 [TODO] - Can't use an Iterator with a DynLexPad PMC 40153 [CAGE] TEST_PROG 40151 [TODO] Remove set_pmc vtable method 6 - 7 weeks old 40138 [TODO] Tcl - add tcl's tests into our repository 40132 [TODO] Remove set_pmc vtable method 40124 [TODO] Document HLL mappings 40123 [TODO] push_eh + .param for argument mismatch errors 40106 [PATCH] 15 more tests work for PGE::P5Regex 7 - 8 weeks old 40090 [TODO] Tcl - make 'tcl.pbc --pir' work. 40072 [CAGE] tools/dev/mk_manifest_and_skip.pl requires svn 40066 rewrite ResizeableBooleanArray 40060 [CAGE] Fix non-symbol-table namespace pollution in public headers 40059 [CAGE] Fix symbol table namespace pollution 40053 Empty PGE rule causes error. rule x { } 8 - 9 weeks old 40010 [TODO] Add a mutex to eval_nr in compilers/imcc/parser_util.c 39992 [TODO] t/op/01-parse_ops.t: figure out how to test parsing of pmc constant parameters 39939 [TODO] exhaustively test new {set,get}*global and get*namespace opcodes 39932 [TODO] enable bulk operations in rt 39927 [TODO] named/slurpy parameters for PMC methods 9 - 10 weeks old 39913 [BUG] TGE - Can't use } in the transform definitions. 39908 [BUG] IMCC treats $S as a non-register instead of throwing an error 39855 [CAGE] configuration: define MIN/MAX macros for all integral typedefs 10 - 11 weeks old 39852 [TODO] Tcl - Create the ::tcl namespace properly 39851 [BUG] .HLL doesn't reset the .namespace 39845 [TODO] Better IMCC Errors: unexpected IDENTIFIER 39844 [BUG] Parrot doesn't do args checking for a sub without params 39833 [TODO] Tcl - Make [rename] handle namespaces 39827 [TODO] [CAGE] implement is_abs_path() 39824 [CAGE] tools/dev/check_source_standards.pl -- this should be a test 39802 [PATCH] [CAGE] turning up the warnings levels in gcc as much as we can 39784 Make Parrot's default namespace be untyped 11 - 12 weeks old 39738 bind fails with errno EADDRNOTAVAIL on darwin and FreeBSD 12 - 13 weeks old 39648 PGE - bad variable name 13 - 14 weeks old 14 - 15 weeks old 39430 Method cache not always invalidated 15 - 16 weeks old 39329 Check to make sure PMC_str_val, etc. are used appropriately 16 - 17 weeks old 17 - 18 weeks old 39197 [CAGE] lib/Parrot/Test.pm ignores core dumps failures! 18 - 19 weeks old 19 - 20 weeks old 20 - 21 weeks old 39051 Test failure in t/pmc/objects_62.pasm (attributes) --- Overview of Open Issues Platform Severity Tag Lang aix 0abandoned 05005threads 0 Amber0 All 2fatal 3bounce0 BASIC0 bsdos 0High 0Bug 29 bc 0 cygwin0low 1compiler 0 befunge 0 cygwin_nt 0medium0configure 0 bf 0 darwin0none 0core 0 cola 0 dec_osf 0Normal1dailybuild0 forth0 dgux 0unknown 0docs 0 jako 0 dos 0Wishlist 3duplicate 0 Lisp 0 dynixptx 0 install 1 m4 0 freebsd 0 library 0 ook 0 generic 0 notabug 0 perl60 gnu 0 notok 0 plot 0 HPUX 0 ok0 punie1 irix 0 Patch23 python 0 irix640 regex 0 ruby 0 Linux 1 sendToCPAN0 scheme 0 lynxos0 Todo196 tcl 30 mac 0 unknown 0 urm 0 machten 0 utilities 0 Zcode0 maco
Re: Nitpick my Perl6 - parametric roles
HaloO, Sam Vilain wrote: Anyone care to pick holes in this little expression of some Perl 6 core types as collections? I mean, other than missing methods ;) My comments follow. role Collection[\$types] { has Seq[$types] @.members; } This is a little wrapper that ensures that collections have got a @.members sequence of arbitrary type. This immediately raises the question how Seq is defined. role Set[::T = Item] does Collection[T] where { all(.members) =:= one(.members); }; Nice usage of junctions! But how is the assertion of uniqueness transported into methods that handle adding of new values? In other words: I doubt that this comes freely out of the type systems inner workings but is more a statement of the intentions of a Set. Which leads to the question when this where clause will be checked or used to base MMD decisions. role Pair[::K = Item, ::V = Item] does Seq[K,V] { method key of K { .[0] } method value of V { .[1] } }; role Mapping[::K = Item, ::V = Item] does Collection[Pair[K,V]] { all(.members).does(Pair) and all(.members).key =:= one(.members).key; } I guess this is a typo and you wanted a where clause. The first assertion of the members doing the Pair role should be guaranteed by using Pair as the type argument when instantiating the Collection role. Are you sure that the underlying Seq type handles the one and two parameter forms you've used so far? role Hash[Str ::K, ::V = Item] does Mapping[K, V] Will the Str assertion not be too specific for non-string hashes? where { all(.members).key == one(.members).key } { method post_circumfix:<{ }> (K $key) of V|Undefined { Nice union type as return type. But isn't the type name Undef? my $seq = first { .key == $key } &.members; Wasn't that @.members? $seq ?? $seq.value :: undef; Ternary is spelled ?? !! now. } } role ArrayItem[::V = Item] does Seq[Int, V] { method index of Int { .[0] } method value of Item { .[1] } }; Here we see the two parameter version of Seq at work. role Array of Collection[ArrayItem] where { all(.members).index == one(.members).index } { method post_circumfix:<[ ]> (Int $index) of Item { my $seq = first { .index == $index } &.members; Is this first there a grep-like function? Shouldn't it then read 'first { .index == $index }, @.members'? $seq ?? $seq.value :: undef; } } I'll take the feedback I get, and try to make a set of Perl 6 classes in the pugs project that look and feel just like regular Perl 6 hash/arrays but are expressed in more elementary particles. This might be very useful in future debates about these types. But I think everything hinges on the basic Seq type. Regards, TSa. --
Re: Nitpick my Perl6 - parametric roles
TSa wrote: > role Set[::T = Item] does Collection[T] where { > all(.members) =:= one(.members); > }; Nice usage of junctions! But buggy - one means *exactly* one. So for an array of more than 1 element, all(@array) never equals one(@array) - if they're all the same, it's more than 1, otherwise it's 0. all(.members) =:= any(.members) would also not work, as it will try to match each member with some other or same member of the array. It will always return true, in other words, as each element of the array is equal to itself. This leaves all(.members) =:= .members[0], possibly extra with non-emptiness test. Miro
Re: Nitpick my Perl6 - parametric roles
HaloO, Miroslav Silovic wrote: TSa wrote: Nice usage of junctions! But buggy - one means *exactly* one. So for an array of more than 1 element, all(@array) never equals one(@array) - if they're all the same, it's more than 1, otherwise it's 0. Doesn't all(1,2,3) == one(1,2,3) expand the all junction first? So that we end up with 1 == one(1,2,3) && 2 == one(1,2,3) && 3 == one(1,2,3) which is true. In the case of duplicated entries we get a false if the one-junction supports that. That is, how does e.g. one(1,1,2) work? Is it failing for 1? Regards, --
Mutability vs Laziness
Carried over form IRC to placeholder the conversation as I saw it: We define the following in S06 as immutable types: ListLazy Perl list (composed of Seq and Range parts) Seq Completely evaluated (hence immutable) sequence Range Incrementally generated (hence lazy) sequence Set Unordered Seqs that allow no duplicates JunctionSets with additional behaviours PairSeq of two elements that serves as a one-element Mapping Mapping Pairs with no duplicate keys It seems to me that there are three core attributes, each of which has two states: Mutability: true, false Laziness: true, false Ordered: true, false There are, thus, eight types of containers, but two (unordered, mutable, lazy/eager) don't really work very well, so let's say 6: Ordered, Immutable, Eager: Seq Ordered, Immutable, Lazy: Range and/or Seq of Range? Ordered, Mutable, Eager: ? Ordered, Mutable, Lazy: Array Unordered, Immutable, Eager: Set Unordered, Immutable, Lazy: x and/or Set of x? In that last example, x is "an unordered range", though we don't have such a type. Basically, this is something like any(a..b). The real question in my mind, though is this: do we need to call something Lazy (as we currently do in S29), or should we just call it List or Array depending on its mutability?
[svn:perl6-synopsis] r12398 - doc/trunk/design/syn
Author: larry Date: Mon Sep 25 10:13:23 2006 New Revision: 12398 Modified: doc/trunk/design/syn/S02.pod doc/trunk/design/syn/S03.pod doc/trunk/design/syn/S06.pod Log: Slaughter of special [,], now is just listop form of [...] To support |func() syntax, | is the new * (desigilized) Modified: doc/trunk/design/syn/S02.pod == --- doc/trunk/design/syn/S02.pod(original) +++ doc/trunk/design/syn/S02.podMon Sep 25 10:13:23 2006 @@ -12,9 +12,9 @@ Maintainer: Larry Wall <[EMAIL PROTECTED]> Date: 10 Aug 2004 - Last Modified: 22 Sept 2006 + Last Modified: 25 Sept 2006 Number: 2 - Version: 71 + Version: 72 This document summarizes Apocalypse 2, which covers small-scale lexical items and typological issues. (These Synopses also contain @@ -670,7 +670,6 @@ @ ordered array % unordered hash (associative array) & code/rule/token/regex -| capture/arguments/match :: package/module/class/role/subset/enum/type/grammar @@ multislice view of @ @@ -818,22 +817,14 @@ $$args; # same as "$args as Scalar" or "Scalar($args)" @$args; # same as "$args as Array" or "Array($args)" %$args; # same as "$args as Hash" or "Hash($args)" -|$args; # all of the above When cast into an array, you can access all the positional arguments; into a hash, all named arguments; into a scalar, its invocant. -When stored in a variable using the C<|> sigil, the capture autointerpolates -into argument lists much like C<@> autoflattens into lists: - -|args := \($a, @b, :option($c)); -somefunc(|args); # same as somefunc($a, @b, :option($c)) - All prefix sigil operators accept one positional argument, evaluated in scalar context as a rvalue. They can interpolate in strings if called with parentheses. The special syntax form C<$()> translates into C<$( $/ )> -to operate on the current match object; the same applies to C<@()>, C<%()> and -C<|()> forms. +to operate on the current match object; the same applies to C<@()> and C<%()>. C objects fill the ecological niche of references in Perl 6. You can think of them as "fat" references, that is, references that @@ -2153,9 +2144,10 @@ =item * -The C<[,]> list operator may be used to force list context on its +The C<|> prefix operator may be used to force "capture" context on its argument and I defeat any scalar argument checking imposed by -subroutine signature declarations. This list flattens lazily. +subroutine signature declarations. Any resulting list arguments are +then evaluated lazily. =item * Modified: doc/trunk/design/syn/S03.pod == --- doc/trunk/design/syn/S03.pod(original) +++ doc/trunk/design/syn/S03.podMon Sep 25 10:13:23 2006 @@ -12,7 +12,7 @@ Maintainer: Larry Wall <[EMAIL PROTECTED]> Date: 8 Mar 2004 - Last Modified: 23 Sept 2006 + Last Modified: 25 Sept 2006 Number: 3 Version: 68 @@ -64,9 +64,8 @@ =item * Unary C<~> now imposes a string (C) context on its argument, and C<+> imposes a numeric (C) context (as opposed to being a no-op in Perl 5). Along the same lines, C imposes -a boolean (C) context, and the C<[,]> list operator imposes -a function-arguments (C) context on its arguments (as does -the C<|> sigil when used as an operator). +a boolean (C) context, and the C<|> unary operator imposes +a function-arguments (C) context on its argument. Unary sigils impose the container context implied by their sigil. As with Perl 5, however, C<$$foo[bar]> parses as C<( $($foo) )[bar]>, so you need C<$($foo[bar])> to mean the other way. @@ -906,14 +905,11 @@ return a boolean for either 1 or 0 arguments. Negated operators return C, and all the rest return C. -You can also make a reduce operator of the comma operator. This has -the effect of dereferencing its arguments into another argument list -as if they'd been placed there directly. +You can also make a reduce operator of the comma operator. This is just +the list operator form of the C<< circumfix:<[ ]> >> anonymous array composer: -@args = [EMAIL PROTECTED],1,2,3; -push [,] @args;# same as push(@foo: 1,2,3) - -See S06 for more. +[1,2,3]# make new Array: 1,2,3 +[,] 1,2,3 # same thing You may also reduce using the semicolon second-dimension separator: @@ -968,7 +964,7 @@ [^^]() # Bool::False [//]() # undef [=]() # undef(same for all assignment operators) -[,]() # () +[,]() # [] [¥]() # [] User-defined operators may define their own identity values, but @@ -1023,9 +1019,7 @@ and more obviously nonsensical.) A reduce operator returns only a scalar result regardless of context. -(Even C<[,]> returns a single C object which is then spliced -into the outer argument list.) To return all
Re: Perl6 "style-guide"
On Sep 20, 2006, at 6:16 PM, Darren Duncan wrote: At 4:56 PM +0200 9/20/06, Fagyal Csongor wrote: I was wondering if there is (or there should be) a documentation on how to elegantly write Perl6 code. I have found that Damian's "Perl Best Practices" still works very well for Perl 6 code, so I still apply that where reasonably possible. And in fact, I expect that PBP was written to be forward compatible to Perl 6, as it could describe styles that should be natural in Perl 6, even if less so in Perl 5. Does anyone want to start a port of Perl::Critic to Perl6? :-) Chris -- Chris Dolan, Software Developer, http://www.chrisdolan.net/ Public key: http://www.chrisdolan.net/public.key vCard: http://www.chrisdolan.net/ChrisDolan.vcf
FYI improved pugs smokes
Hi folks, Read the journal http://pugs.blogs.com/pugs/2006/09/check_smoke_res.html Follow the link: http://m19s28.vlinux.de/cgi-bin/pugs-smokeserv.pl? Click at a recent entry with a SYN link Then click on "02 Syntax" Then on e.g.: - Show the snippet from t/syntax/unicode.t (line 7 ~ line 85 — 26 √, 0 ×) - This expands the tests related to this topic in the html and even shows test success status. Really cool. Q: is this helpful for parrot pdds? Q: implementable? leo
Re: FYI improved pugs smokes
On 9/25/06, Leopold Toetsch <[EMAIL PROTECTED]> wrote: Hi folks, Read the journal http://pugs.blogs.com/pugs/2006/09/check_smoke_res.html Follow the link: http://m19s28.vlinux.de/cgi-bin/pugs-smokeserv.pl? Click at a recent entry with a SYN link Then click on "02 Syntax" Then on e.g.: - Show the snippet from t/syntax/unicode.t (line 7 ~ line 85 — 26 √, 0 ×) - This expands the tests related to this topic in the html and even shows test success status. Really cool. Q: is this helpful for parrot pdds? indeed. it's super cool. i've been working with agent zhang and others to improve this... Q: implementable? ...and have been working on an implementation. ideally, i'd like to get this coded up in pir, but i'm working now on modifying the perl source. my progress has stalled lately, as i seem to have dropped a few tuits of the right flavor. i'll merge my changes with the latest version of smartlinks.pl, and commit something (even if it's broken.) i'll include some comments or a todo list for those with tuits to spare. it does need some extension to work for parrot, particularly because parrot has two sets of design documents, PDDs for most things, and S05 (plus perhaps others) for PGE. i believe a refactoring of the current code will allow it to work for multiple sets of documents. ~jerry
Re: Mutability vs Laziness
Aaron Sherman wrote: It seems to me that there are three core attributes, each of which has two states: Mutability: true, false Laziness: true, false Ordered: true, false I think there's a 4th: exclusivity: whether or not duplicate elements are permitted/exposed (i.e. the difference between a set and a bag). This is orthogonal to orderedness.
Re: Nitpick my Perl6 - parametric roles
TSa wrote: >> role Collection[\$types] { >>has Seq[$types] @.members; >> } > This is a little wrapper that ensures that collections have got > a @.members sequence of arbitrary type. This immediately raises > the question how Seq is defined. > [...and later...] > Are you sure that the underlying Seq type handles the one and > two parameter forms you've used so far? Ah, yes, a notable omission. I understood a Seq as a list with individual types for each element, which are applied positionally. The superclass for things like Pair. Here's a quick mock-up of what I mean: role Seq[ \$types ] { submethod COMPOSE { # a la BUILD for classes loop( my $i = 0; $i < $types.elems; $i++ ) { # assumption: "self" here is the class # we're composing to, and "has" is a class # method that works a little like Moose self.has( $i++ => (isa => $types.[$i]) ); } } my subset MySeqIndex of Int where { 0 <= $_ < $types.elems }; method post_circimfix:<[ ]>( $element: MySeqIndex ) { $?SELF.$element; } } Seq is certainly interesting for various reasons. One is that it is a parametric role that takes an arbitrary set of parameters. In fact, it's possible that the type arguments are something more complicated than a list (making for some very "interesting" Seq types); the above represents a capture, but the above code treats it was a simple list. >> role Set[::T = Item] does Collection[T] where { >> all(.members) =:= one(.members); >> }; > > Nice usage of junctions! But how is the assertion of > uniqueness transported into methods that handle adding > of new values? I haven't defined any mutable state yet; it's still "pure". I'd expect mutability to be a different role, and a set of primitives that work on this level by returning a new set with the changes made. In fact the mutable Set could re-use those primitives, by just having a Set as a member (that 'handles' the Set role methods), and automatically changing that member each time a change is made, to point to the new Set with the new contents. Which all sounds very inefficient and scary until you realise what happens inside generative GC VMs that support STM. >> role Mapping[::K = Item, ::V = Item] does Collection[Pair[K,V]] { >> all(.members).does(Pair) and >> all(.members).key =:= one(.members).key; >> } > > I guess this is a typo and you wanted a where clause. The first > assertion of the members doing the Pair role should be guaranteed > by using Pair as the type argument when instantiating the Collection > role. Well spotted; yes, that is superfluous. >> role Hash[Str ::K, ::V = Item] does Mapping[K, V] > > Will the Str assertion not be too specific for non-string hashes? Another assumption I make here is that there is a basic type "Hash", which as its name suggests, is all about hashing strings, and that the more general form is called "Mapping" where any object can be the source, not just Str subtypes. Thanks for your other nitpicks and comments - much appreciated! Sam. >> where { all(.members).key == one(.members).key } >> { >> method post_circumfix:<{ }> (K $key) of V|Undefined { > > Nice union type as return type. But isn't the type name Undef? > >> my $seq = first { .key == $key } &.members; > > Wasn't that @.members? > >> $seq ?? $seq.value :: undef; > > Ternary is spelled ?? !! now. > > >> } >> } >> >> role ArrayItem[::V = Item] does Seq[Int, V] { >> method index of Int { .[0] } >> method value of Item { .[1] } >> }; > > Here we see the two parameter version of Seq at work. > > >> role Array of Collection[ArrayItem] >> where { all(.members).index == one(.members).index } >> { >> method post_circumfix:<[ ]> (Int $index) of Item { >> my $seq = first { .index == $index } &.members; > > Is this first there a grep-like function? Shouldn't it then > read 'first { .index == $index }, @.members'? > > >> $seq ?? $seq.value :: undef; >> } >> } >> >> I'll take the feedback I get, and try to make a set of Perl 6 classes in >> the pugs project that look and feel just like regular Perl 6 hash/arrays >> but are expressed in more elementary particles. > > This might be very useful in future debates about these types. But > I think everything hinges on the basic Seq type. > > > Regards, TSa.
Re: Mutability vs Laziness
Aaron Sherman wrote: > Carried over form IRC to placeholder the conversation as I saw it: > > We define the following in S06 as immutable types: > > ListLazy Perl list (composed of Seq and Range parts) > Seq Completely evaluated (hence immutable) sequence > Range Incrementally generated (hence lazy) sequence > Set Unordered Seqs that allow no duplicates > JunctionSets with additional behaviours > PairSeq of two elements that serves as a one-element Mapping > Mapping Pairs with no duplicate keys > > It seems to me that there are three core attributes, each of which has > two states: > > Laziness: true, false > Mutability: true, false > Ordered: true, false I don't think "Ordered" is an attribute of a collection other than in the abstract, user-centric sense - it is a type parameter difference (though also there are method differences etc). Things that are not ordered map from items to presence (or themselves, if you prefer). Things that are ordered map from array indices to items. > There are, thus, eight types of containers, but two (unordered, mutable, > lazy/eager) don't really work very well, so let's say 6: Mutable sets don't work? I don't see why not. > Ordered, Immutable, Eager: Seq > Ordered, Immutable, Lazy: Range and/or Seq of Range? > Ordered, Mutable, Eager: ? > Ordered, Mutable, Lazy: Array > Unordered, Immutable, Eager: Set > Unordered, Immutable, Lazy: x and/or Set of x? > > In that last example, x is "an unordered range", Sounds a bit like an iterator. Sam.
Common Serialization Interface
Both Data::Dumper and Storable provide hooks to customize serialization ($Data::Dumper::Freezer|Toaster, STORABLE_freeze|_thaw). Other modules like YAML and Clone could also possibly reuse a common state marshalling interface. Is there some common element to this process which can be gathered into a Serialize role with a default implementation? Does the meta information or object construction process change the needs for Perl 6? Brad -- It is written that the priest Shungaku said, "In just refusing to retreat from something one gains the strength of two men." This is interesting.-- Hagakure http://bereft.net/hagakure/
Re: Common Serialization Interface
Brad Bowman wrote: > > Both Data::Dumper and Storable provide hooks to customize serialization > ($Data::Dumper::Freezer|Toaster, STORABLE_freeze|_thaw). > Other modules like YAML and Clone could also possibly reuse a > common state marshalling interface. > > Is there some common element to this process which can be gathered > into a Serialize role with a default implementation? There is already ".yaml" to serialize to yaml and ".perl" to serialize to Perl (I'm not sure what the limits are round-tripping Perl this way). They can be returned to Perl in a consistent way, too: eval($yaml, :lang); Still, these options may not substitute for the kind of role-based solution you have mind. Mark
Re: Common Serialization Interface
On Mon, Sep 25, 2006 at 09:02:56PM -0500, Mark Stosberg wrote: : Brad Bowman wrote: : > : > Both Data::Dumper and Storable provide hooks to customize serialization : > ($Data::Dumper::Freezer|Toaster, STORABLE_freeze|_thaw). : > Other modules like YAML and Clone could also possibly reuse a : > common state marshalling interface. : > : > Is there some common element to this process which can be gathered : > into a Serialize role with a default implementation? : : There is already ".yaml" to serialize to yaml and ".perl" to serialize : to Perl (I'm not sure what the limits are round-tripping Perl this way). One thing that makes an enormous practical difference is whether the entire serialized string must be in memory or not. (I've been trying to work with a 37M yaml file recently, sigh...) : They can be returned to Perl in a consistent way, too: : : eval($yaml, :lang); : : Still, these options may not substitute for the kind of role-based : solution you have mind. I'm not sure it's wise to overload eval this way. Seems like a great way to defeat MMD. Plus I really want a file interface so I don't have to slurp a 37M string, which in turn requires a 400M stack allocation currently. Seems to want even more heap after that, and then it really starts thrashing... Larry
Re: Nitpick my Perl6 - parametric roles
On 9/25/06, Miroslav Silovic <[EMAIL PROTECTED]> wrote: TSa wrote: > > > role Set[::T = Item] does Collection[T] where { > > all(.members) =:= one(.members); > > }; > > Nice usage of junctions! > But buggy - one means *exactly* one. So for an array of more than 1 element, all(@array) never equals one(@array) - if they're all the same, it's more than 1, otherwise it's 0. Yeah, that would've been cool. Are we left with asserting C? That'd be pretty close to the original elegance. Ashley Winters
Re: Nitpick my Perl6 - parametric roles
At 7:28 PM -0700 9/25/06, Ashley Winters wrote: On 9/25/06, Miroslav Silovic <[EMAIL PROTECTED]> wrote: TSa wrote: > role Set[::T = Item] does Collection[T] where { > all(.members) =:= one(.members); > }; > Nice usage of junctions! But buggy - one means *exactly* one. So for an array of more than 1 element, all(@array) never equals one(@array) - if they're all the same, it's more than 1, otherwise it's 0. Yeah, that would've been cool. Are we left with asserting C? That'd be pretty close to the original elegance. Ashley Winters Unless I'm mistaken, you may be going about this the wrong way. Within a system that already has an underlying set-like type, the Junction in this case, a test for uniqueness is (pardon any spelling): all(@items).elements.size === @items.size The all() will strip any duplicates, so if the number of elements in all(@items) is the same as @items, then @items has no duplicates. Similarly, if @items is a list of Pair (such as when you're implementing a Mapping), and you want to assert that their keys are all distinct, then this variation (pardon any spelling) would do it: all(@items.map:{ .key }).elements.size === @items.size Incidentally, a unique-key constraint on an RM relation or table is like the latter as well, but substitute "key" for the name(s) of the attribute or column. On the other hand, if you're using the above Set to implement the Junction in the first place, we can't use all/any/one/none etc in the definition. -- Darren Duncan
[svn:perl6-synopsis] r12417 - doc/trunk/design/syn
Author: audreyt Date: Mon Sep 25 20:49:59 2006 New Revision: 12417 Modified: doc/trunk/design/syn/S02.pod doc/trunk/design/syn/S04.pod Log: * S02: Introduce the :$$x form in adverbial pair parsing. * S02/S04: Canonicalize "item" as the unary context enforcer, so that the name "Scalar" can unabiguous mean the mutable container class. Modified: doc/trunk/design/syn/S02.pod == --- doc/trunk/design/syn/S02.pod(original) +++ doc/trunk/design/syn/S02.podMon Sep 25 20:49:59 2006 @@ -12,9 +12,9 @@ Maintainer: Larry Wall <[EMAIL PROTECTED]> Date: 10 Aug 2004 - Last Modified: 25 Sept 2006 + Last Modified: 26 Sept 2006 Number: 2 - Version: 72 + Version: 73 This document summarizes Apocalypse 2, which covers small-scale lexical items and typological issues. (These Synopses also contain @@ -1481,6 +1481,8 @@ a => $a:$a a => @a:@a a => %a:%a +a => $$a :$$a +a => @$$a :@$$a (etc.) a => %foo %foo: Note that as usual the C<{...}> form can indicate either a closure or a hash @@ -2142,6 +2144,8 @@ really does exactly the same thing as putting a list in parentheses with at least one comma. But it's more readable in some situations.) +To force a non-flattening scalar context, use the "C" operator. + =item * The C<|> prefix operator may be used to force "capture" context on its Modified: doc/trunk/design/syn/S04.pod == --- doc/trunk/design/syn/S04.pod(original) +++ doc/trunk/design/syn/S04.podMon Sep 25 20:49:59 2006 @@ -12,9 +12,9 @@ Maintainer: Larry Wall <[EMAIL PROTECTED]> Date: 19 Aug 2004 - Last Modified: 24 Sep 2006 + Last Modified: 26 Sep 2006 Number: 4 - Version: 40 + Version: 41 This document summarizes Apocalypse 4, which covers the block and statement syntax of Perl. @@ -933,7 +933,7 @@ and not care about whether the function is being called in scalar or list context. To return an explicit scalar undef, you can always say -return scalar(undef); +return item(undef); Then in list context, you're returning a list of length 1, which is defined (much like in Perl 5). But generally you should be using
External PDD Checkin
Hi all, I've added some more thoughts, principles, and questions to the external API draft PDD. I also started two sections on the API. I've changed some of the function signatures in an attempt to make things more consistent. Feedback would be wonderful, even if it's only "This is very sane and someone should code it." See docs/pdds/clip/pdd10_embedding.pod. -- c
[svn:parrot-pdd] r14732 - in trunk: . docs/pdds/clip
Author: chromatic Date: Mon Sep 25 23:06:17 2006 New Revision: 14732 Modified: trunk/docs/pdds/clip/pdd10_embedding.pod Changes in other areas also in this revision: Modified: trunk/ (props changed) Log: Added more principles and gotchas. Added outline for API documentation. Filled in two sections of API guidelines; ready for comments on list. Modified: trunk/docs/pdds/clip/pdd10_embedding.pod == --- trunk/docs/pdds/clip/pdd10_embedding.pod(original) +++ trunk/docs/pdds/clip/pdd10_embedding.podMon Sep 25 23:06:17 2006 @@ -23,11 +23,11 @@ =over 4 -=item - access to special features/libraries/languages Parrot provides +=item * access to special features/libraries/languages Parrot provides -=item - need an interpreter for a DSL or existing language +=item * need an interpreter for a DSL or existing language -=item - want to run Parrot on another platform or environment (dedicated +=item * want to run Parrot on another platform or environment (dedicated hardware, in a web server, et cetera) =back @@ -36,9 +36,9 @@ =over 4 -=item - need something NCI doesn't provide +=item * need something NCI doesn't provide -=item - writing a custom PMC +=item * writing a custom PMC =back @@ -46,27 +46,37 @@ =over 4 -=item - only ever use opaque pointers +=item * only ever use opaque pointers -=item - should be able to communicate through PMCs +=item * should be able to communicate through PMCs -=item - minimize conversions to and from C data +=item * minimize conversions to and from C data =over 4 -=item - perhaps macros; Ruby does this fairly well and Perl 5 does this +=item * perhaps macros; Ruby does this fairly well and Perl 5 does this poorly -=item - minimize the number of necessary functions +=item * minimize the number of necessary functions -=item - probably can follow core Parrot code to some extent, but beware the +=item * probably can follow core Parrot code to some extent, but beware the Perl 5 problem =over 4 -=item - do not expose Parrot internals that may change +=item * do not expose Parrot internals that may change -=item - probably includes vtable methods on PMCs +=over 4 + +=item * minimize the number of headers used + +=item * minimize the number of Parrot types exposed + +=item * follow boundaries similar to those of PIR where possible + +=back + +=item * probably includes vtable methods on PMCs =back @@ -78,44 +88,51 @@ =over 4 -=item - who handles signals? +=item * who handles signals? -=item - who owns file descriptors and other Unix resources? +=item * who owns file descriptors and other Unix resources? -=item - is there an exception boundary? +=item * is there an exception boundary? -=item - namespace issues -- especially key related +=item * namespace issues -- especially key related -=item - probably a continuation/control flow boundary +=item * probably a continuation/control flow boundary -=item - packfiles and compilation units probably too much information for +=item * packfiles and compilation units probably too much information for either -=item - do not let MMD and other implementation details escape +=item * do not let MMD and other implementation details escape -=item - okay to require some PBC/PIR/PASM for handling round-trip data +=item * okay to require some PBC/PIR/PASM for handling round-trip data -=item - Parrot should not spew errors to STDERR when embedded +=item * Parrot should not spew errors to STDERR when embedded -=item - const_string() is a real pain, especially with necessary deallocation +=item * who allocates and deallocates resources passed through the boundary +level? -=item - should be access to Parrot's event loop when embedded +=item * should be access to Parrot's event loop when embedded -=item - passing var args to Parrot subs likely painful +=item * passing var args to Parrot subs likely painful =over 4 -=item - perhaps macros/functions to add parameters to call +=item * perhaps macros/functions to add parameters to call -=item - build up a call signature somehow? +=item * build up a call signature somehow? -=item - some abstraction for a call frame? +=item * some abstraction for a call frame? =back -=item - compiling code from a string should return the PMC Sub entry point +=item * compiling code from a string should return the PMC Sub entry point (:main) +=item * are there still directory path, loading, and deployment issues? + +=item * how do dynamic oplibs and custom PMCs interact? + +=item * what's the best way to handle character sets and Unicode? + =back =head1 DEFINITIONS @@ -132,9 +149,101 @@ Implementation details. +Simplicity is the main goal; it should be almost trivial to embed Parrot in an +existing application. It must be trivial to do the right thing; the APIs must +make it so much easier to work correctly than to make mistakes. This means,