Re: some questions about S02(type)
On Fri, Apr 3, 2009 at 10:52 PM, Moritz Lenz wrote: > Xiao Yafeng wrote: > > 1. Could I set multi-return type?like > > sub test as (Int, Str) {...} > > "as" is coercion - so to what would it coerce? Int or Str? How could the > compiler know? Or do you mean something like a tuple? > as what Timothy S. Nelson say > > > 2. set is unordered collection of values, subset is new type. People are > > apt to confuse the two concepts. > > Note that people never write "subset" in their code, the write things like > sub f($x where { ... } ) and the "where" constructs the subset type. I > don' think that's > I think subset can define a new type, I'm custom to set it at head of code, subset name_string of Str where {~~/^^name/}; am I wrong? > > > 3. Could I define primary key for a bag variable? > > All items in a Bag are "primary keys", but there's no data additional > data associated with it. > I mean whether I can see Set as a table and Bag as a table with a unique constraint? like: subset test of Bag(test_name Str, test_ID Int, primary key(test_ID))
Multi-Dimensional arrays
Am I right that multi-dimensional arrays do not yet work fully in Rakudo?
Re: some questions about S02(type)
On Sat, 4 Apr 2009, Xiao Yafeng wrote: 3. Could I define primary key for a bag variable? All items in a Bag are "primary keys", but there's no data additional data associated with it. I mean whether I can see Set as a table and Bag as a table with a unique constraint? like: subset test of Bag(test_name Str, test_ID Int, primary key(test_ID)) I don't think you can really do something like that. Perl 6 as specified leaves many things up to libraries. Implementing a Table type will no doubt be one of those things. I would like to have a Table type that will work well with the Tree/Plex type that I am working on. In the meantime, a table would need to be represented as an array of hashes, or a hash of arrays. HTH, - | Name: Tim Nelson | Because the Creator is,| | E-mail: wayl...@wayland.id.au| I am | - BEGIN GEEK CODE BLOCK Version 3.12 GCS d+++ s+: a- C++$ U+++$ P+++$ L+++ E- W+ N+ w--- V- PE(+) Y+>++ PGP->+++ R(+) !tv b++ DI D G+ e++> h! y- -END GEEK CODE BLOCK-
r26069 - docs/Perl6/Spec
Author: masak Date: 2009-04-04 11:32:02 +0200 (Sat, 04 Apr 2009) New Revision: 26069 Modified: docs/Perl6/Spec/S09-data.pod Log: [S09] added table of operations that autovivify Modified: docs/Perl6/Spec/S09-data.pod === --- docs/Perl6/Spec/S09-data.pod2009-04-04 04:48:37 UTC (rev 26068) +++ docs/Perl6/Spec/S09-data.pod2009-04-04 09:32:02 UTC (rev 26069) @@ -1230,6 +1230,19 @@ autovivification is defined in terms of protoobjects rather than failure, it still works under "use fatal". +This table solidifies the intuition that an operation pertaining to some data +structure causes the protoobject to autivivify to such an object: + +operationautovivifies to +==== +push, unshift, .[] Array +.{}, .<> Hash + +In addition to the above data structures autovivifying, C<++> and C<--> will +cause an C to appear, C<~=> will create a C etc; but these are +natural consequences of the operators working on C, qualitatively +different from autovivifying containers. + The type of the protoobject returned by a non-successful lookup should be identical to the type that would be returned for a successful lookup.
Re: Multi-Dimensional arrays
Peter (>): > Am I right that multi-dimensional arrays do not yet work fully in Rakudo? Yes, you are. That is to say, you can't do this yet: my @a[4;2]; # Valid indices are 0..3 ; 0..1 There's nothing stopping you from creating an array of arrays, though. // Carl
r26081 - docs/Perl6/Spec
Author: masak Date: 2009-04-04 14:57:29 +0200 (Sat, 04 Apr 2009) New Revision: 26081 Modified: docs/Perl6/Spec/S09-data.pod Log: [S09] removed .<> from the table It's just sugar anyway. pmurias++ for pointing that out. Modified: docs/Perl6/Spec/S09-data.pod === --- docs/Perl6/Spec/S09-data.pod2009-04-04 11:09:55 UTC (rev 26080) +++ docs/Perl6/Spec/S09-data.pod2009-04-04 12:57:29 UTC (rev 26081) @@ -1236,7 +1236,7 @@ operationautovivifies to ==== push, unshift, .[] Array -.{}, .<> Hash +.{} Hash In addition to the above data structures autovivifying, C<++> and C<--> will cause an C to appear, C<~=> will create a C etc; but these are
r26090 - docs/Perl6/Spec
Author: s1n Date: 2009-04-04 20:45:14 +0200 (Sat, 04 Apr 2009) New Revision: 26090 Modified: docs/Perl6/Spec/S16-io.pod Log: [spec] minor touch-ups to better format the pod for perl5's perldoc tool. Modified: docs/Perl6/Spec/S16-io.pod === --- docs/Perl6/Spec/S16-io.pod 2009-04-04 15:57:31 UTC (rev 26089) +++ docs/Perl6/Spec/S16-io.pod 2009-04-04 18:45:14 UTC (rev 26090) @@ -1,4 +1,3 @@ - =encoding utf8 =head1 Title @@ -62,8 +61,8 @@ syntax: { - temp $*OUT = open $newfile, :w; - foo() # all stdout goes to $newfile +temp $*OUT = open $newfile, :w; +foo() # all stdout goes to $newfile } # stdout reverts to outer scope's definition @@ -77,21 +76,23 @@ =head2 User role -role User { - has $username; # Username (some descendants(?) may want to implement a real $name) - has $id; # User ID - has $dir; # Home directory for files -} +role User { +has $username; # Username (some descendants(?) may want to implement a real $name) +has $id; # User ID +has $dir; # Home directory for files +} +=over + =item new - method User new($Username?, $UID?) {...} +method User new($Username?, $UID?) {...} Creates a new User object, fetching the information either by username or user ID. =item write - method write() {...} +method write() {...} Tries to write the current User object to the user database. This may well fail. @@ -103,50 +104,56 @@ When converted to a Num, returns $uid. +=back + =head2 OS::Unix::User role -role OS::Unix::User does User { - has $password; - has $gid; - has $gecos; - has $shell; -} +role OS::Unix::User does User { +has $password; +has $gid; +has $gecos; +has $shell; +} All the information is naturally fetched from the system via getpwuid, getpwnam, or the like. =head2 Group role -role Group { - has $name; - has $id; - has @members; -} +role Group { +has $name; +has $id; +has @members; +} +=over + =item new - method Group new(:$Name, :$ID); +method Group new(:$Name, :$ID); =item write - method write(); +method write(); Tries to write the group entry into the system group database. -=head OS::Unix::NameServices role +=back +=head2 OS::Unix::NameServices role + The NameServices role has a bunch of functions that between them will return the whole Name Services database between them, as lists of objects. The lists are specifically intended to be lazy. -role NameServices { - method List of User users() {...} # getpwent, setpwent, endpwent - method List of Groupgroups(){...} # getgrent, setgrent, endgrent - method List of Service services() {...} # getservent, setservent, endservent - method List of Protocol protocols() {...} # getprotoent, setprotoent, endprotoent - method List of Network networks() {...} # getnetent, setnetent, endnetent - method List of Host hosts() {...} # gethostent, sethostent, endhostent -} +role NameServices { +method List of User users() {...} # getpwent, setpwent, endpwent +method List of Groupgroups(){...} # getgrent, setgrent, endgrent +method List of Service services() {...} # getservent, setservent, endservent +method List of Protocol protocols() {...} # getprotoent, setprotoent, endprotoent +method List of Network networks() {...} # getnetent, setnetent, endnetent +method List of Host hosts() {...} # gethostent, sethostent, endhostent +} =head1 Additions @@ -155,5 +162,4 @@ =cut -=encoding utf8 - +=for vim:set expandtab sw=4:
Re: some questions about S02(type)
Timothy S. Nelson wrote: On Sat, 4 Apr 2009, Xiao Yafeng wrote: I mean whether I can see Set as a table and Bag as a table with a unique constraint? like: I think you have that backwards. A Set is conceptually like a Bag with a uniqueness constraint, not the other way around. subset test of Bag(test_name Str, test_ID Int, primary key(test_ID)) I don't think you can really do something like that. Perl 6 as specified leaves many things up to libraries. Implementing a Table type will no doubt be one of those things. I would like to have a Table type that will work well with the Tree/Plex type that I am working on. In the meantime, a table would need to be represented as an array of hashes, or a hash of arrays. Speaking of libraries, I already implemented a table type ... it's called Set::Relation/::V2 and its on CPAN right now ... for Perl 5 ... I still have to port it to Perl 6, unless someone else wants to do that, but I designed it so that would be easy to do. The port could stand for some additional Perl 6 savvyness too. -- Darren Duncan