some questions about S02(type)

2009-04-03 Thread Xiao Yafeng
1. Could I set multi-return type?like
 sub test as (Int, Str) {...}
 my  (Int, Str) sub test {...}
 or my (Int|Num, Str) sub test{...}

2. set is unordered collection of values, subset is new type.  People are
apt to confuse the two concepts.

3. Could I define primary key for a bag variable?


Re: junctions and conditionals

2009-04-03 Thread Miroslav Silovic

Dave Whipp wrote:
I'm thinking that the solution to this issue may be a little more 
radical than to-date: don't permit junctions to be stored in $ 
variables! Instead, require junctions to use a twiggle, to alert the 
reader that the surprises may be lurking.


my $x = 1|2; #error
my $|x = 1|2; # ok

Then you just need to invent some syntax to say that collapse is (or 
perhaps isn't) desired:


if [[ $|x  1 ]] { say $|x collapsed }

The most important thing that this does is that it leaves open the 
option to allow $ variables to hold junctions in some future version 
of Perl, without that future version being constrained by legacy 
semantics.




I'd second the twigil idea. Reason: I'd -really- like perl6 to be 
compilable into an efficient machine code without a JIT magic that we 
can currently only handwave about.


For that, I'd propose a rule of a thumb: ints are ints. Of course, 
floats and other unboxed types should also be just plain unboxed types, 
but I'd like the rule of a thumb to be short and to the point.


So,

int $x = 1|2;

should be an error.

Also,

int $x = 1 but not really a number;

should also be an error or at least a warning that mixin stripping and 
unboxing took place. If you want polymorphic here, use Ints. That'd also 
mean that


my @x of int;

can be implemented as a homogenous int vector, meaning -really- 
efficient and manipulable through the kind of code that modern CPUs are 
really good at (since as soon as you know you won't be lazy, you only 
need to be polymorphic about asking for the beginning of the in-memory 
buffer that can be manipulated directly. Even if that buffer doesn't 
contain all the elements, you can refill it as needed, and that could 
still be fast as long as the other side of the partially-lazy barrier 
also speaks int). Also, as far as I'm aware, there is no tracing VM that 
can create a homogenous arrays for you if you can't already do them.


From the above, the need for twigils in junctions should be apparent.

   Miro



Re: some questions about S02(type)

2009-04-03 Thread Moritz Lenz
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?

 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

 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.

Cheers,
Moritz


Re: some questions about S02(type)

2009-04-03 Thread Moritz Lenz


Moritz Lenz wrote:
 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

... all that confusing.

Forgot to finish the sentence... :/


Re: some questions about S02(type)

2009-04-03 Thread Timothy S. Nelson

On Fri, 3 Apr 2009, 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?


I think he wants something like:



sub example( - Int, Str) {
...
return(3, 4);
}

my($a, $b) = example();
$b.isa('Str') and say b is a string; # says b is a string



	...and hasn't learned the p6isms that express that.  In other words, 
he wants to return multiple values, but enforce certain types on them.



-
| 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-