Re: Decorating Objects with Roles (was Re: Optional binding)

2005-03-09 Thread Larry Wall
On Tue, Mar 08, 2005 at 05:49:54PM -0800, chromatic wrote: : On Tue, 2005-03-08 at 17:39 -0800, Larry Wall wrote: : : > On Tue, Mar 08, 2005 at 03:23:14PM -0800, chromatic wrote: : : > : I could make the argument that it should be possible to decorate an : > : object with a role. If that means g

Re: Decorating Objects with Roles (was Re: Optional binding)

2005-03-08 Thread chromatic
On Tue, 2005-03-08 at 17:39 -0800, Larry Wall wrote: > On Tue, Mar 08, 2005 at 03:23:14PM -0800, chromatic wrote: > : I could make the argument that it should be possible to decorate an > : object with a role. If that means generating a new anonymous class just > : to have a vtable to munge, so

Re: Decorating Objects with Roles (was Re: Optional binding)

2005-03-08 Thread Larry Wall
On Tue, Mar 08, 2005 at 03:23:14PM -0800, chromatic wrote: : I could make the argument that it should be possible to decorate an : object with a role. If that means generating a new anonymous class just : to have a vtable to munge, so be it. Er, how is that different from what we already said? O

Decorating Objects with Roles (was Re: Optional binding)

2005-03-08 Thread chromatic
On Mon, 2005-03-07 at 19:40 -0800, Larry Wall wrote: > On Mon, Mar 07, 2005 at 05:56:12PM -0800, David Storrs wrote: > : Actually, I guess they would have to be...can you apply a role to a > : bare type? > : > : my int does SelectOutputFile; # I would expect this to fail > : my Int d

Re: Optional binding

2005-03-07 Thread Larry Wall
On Mon, Mar 07, 2005 at 08:58:44PM -0800, David Storrs wrote: : Ok, rewrite; is THIS legal?: : : sub foo( Int [EMAIL PROTECTED] is shape(3) ) { ... } : foo(1, 2, undef); Yes, since Int can represent undef. : The sense I'm trying to convey is: : : "Here is my sub. It takes three

Re: Optional binding

2005-03-07 Thread David Storrs
On Mon, Mar 07, 2005 at 07:50:47PM -0800, Larry Wall wrote: > On Mon, Mar 07, 2005 at 05:37:53PM -0800, David Storrs wrote: > : On Mon, Mar 07, 2005 at 04:58:29PM -0800, Larry Wall wrote: > : Is > : there is then any way to explicitly leave off an element. Can I do > : this: > : > : sub foo(

Re: Optional binding

2005-03-07 Thread Larry Wall
On Mon, Mar 07, 2005 at 05:37:53PM -0800, David Storrs wrote: : On Mon, Mar 07, 2005 at 04:58:29PM -0800, Larry Wall wrote: : > : > In fact, we really haven't specified what happens when you say : > : > my Int @a is shape(3) := [1,2]; : > my Int @b is shape(3) := [1,2,3,4]; : > : [...] :

Re: Optional binding

2005-03-07 Thread Larry Wall
On Mon, Mar 07, 2005 at 05:56:12PM -0800, David Storrs wrote: : On Mon, Mar 07, 2005 at 05:15:14PM -0800, Larry Wall wrote: : > On Mon, Mar 07, 2005 at 02:20:47PM -0800, David Storrs wrote: : > : Yes, I know. That's what I meant by "...arrays are objects...(sort : > : > No, they're real objects.

Re: Optional binding

2005-03-07 Thread David Storrs
On Mon, Mar 07, 2005 at 05:15:14PM -0800, Larry Wall wrote: > On Mon, Mar 07, 2005 at 02:20:47PM -0800, David Storrs wrote: > : Yes, I know. That's what I meant by "...arrays are objects...(sort > > No, they're real objects. (Though it's .elems rather than .length, since > we've banished the "l"

Re: Optional binding

2005-03-07 Thread David Storrs
On Mon, Mar 07, 2005 at 04:58:29PM -0800, Larry Wall wrote: > > In fact, we really haven't specified what happens when you say > > my Int @a is shape(3) := [1,2]; > my Int @b is shape(3) := [1,2,3,4]; > [...] > But I also have this nagging feeling that the user wouldn't have > specified

Re: Optional binding

2005-03-07 Thread Larry Wall
On Mon, Mar 07, 2005 at 02:20:47PM -0800, David Storrs wrote: : Yes, I know. That's what I meant by "...arrays are objects...(sort : of)." They are objects in the sense that they are sort of references : and sort of not and that they have behavior built into them : (e.g. C<.length>). They won't a

Re: Optional binding

2005-03-07 Thread Larry Wall
On Mon, Mar 07, 2005 at 10:29:58PM +0100, Aldo Calpini wrote: : Larry Wall wrote: : >Or, assuming you might want to generalize to N dimensions someday, just : > : >sub bar ([EMAIL PROTECTED]) {...} : > : >and deal with it as in Perl 5 as a variadic list. I suppose one could say : > : >sub

Re: Optional binding

2005-03-07 Thread David Storrs
On Mon, Mar 07, 2005 at 05:36:08PM +0100, Aldo Calpini wrote: > David Storrs wrote: > >Urk. I, for one, will definitely find this surprising. I would have > >expected: > > > > x = ; $y = 1; z = 2 3 > > to obtain what you have expected, you need to explicitly treat the array > as a list of value

Re: Optional binding

2005-03-07 Thread Aldo Calpini
Larry Wall wrote: Or, assuming you might want to generalize to N dimensions someday, just sub bar ([EMAIL PROTECTED]) {...} and deal with it as in Perl 5 as a variadic list. I suppose one could say sub bar ([EMAIL PROTECTED] is shape(3)) {...} and get checking on the argument count. if I u

Re: Optional binding

2005-03-07 Thread Larry Wall
On Mon, Mar 07, 2005 at 05:36:08PM +0100, Aldo Calpini wrote: : but then, you could define: : : multi sub bar($x, $y, $z) { ... } : multi sub bar(@coords is shape(3)) { : my($x, $y, $z) = @coords; : return bar($x, $y, $z); : } : : bar(@coords); # ok now Or, assumi

Re: Optional binding

2005-03-07 Thread Aldo Calpini
David Storrs wrote: Urk. I, for one, will definitely find this surprising. I would have expected: x = ; $y = 1; z = 2 3 to obtain what you have expected, you need to explicitly treat the array as a list of values with the unary splat: foo($x, [EMAIL PROTECTED]); But I suppose it's all a qu

Re: Optional binding

2005-03-07 Thread David Storrs
On Sun, Mar 06, 2005 at 11:58:43PM -0800, Larry Wall wrote: > On Sun, Mar 06, 2005 at 02:13:09AM -0700, Luke Palmer wrote: > : What is output: > : > : sub foo($x, ?$y, [EMAIL PROTECTED]) { > : say "x = $x; y = $y; z = @z[]"; > : } > : > : my @a = (1,2,3); > : foo($x, @a);

Re: Optional binding

2005-03-07 Thread Larry Wall
On Mon, Mar 07, 2005 at 03:03:08AM +0200, Yuval Kogman wrote: : On Sun, Mar 06, 2005 at 02:13:09 -0700, Luke Palmer wrote: : > What is output: : > : > sub foo($x, ?$y, [EMAIL PROTECTED]) { : > say "x = $x; y = $y; z = @z[]"; : > } : > : > my @a = (1,2,3); : > foo($x, @a);

Re: Optional binding

2005-03-06 Thread Larry Wall
On Sun, Mar 06, 2005 at 02:13:09AM -0700, Luke Palmer wrote: : What is output: : : sub foo($x, ?$y, [EMAIL PROTECTED]) { : say "x = $x; y = $y; z = @z[]"; : } : : my @a = (1,2,3); : foo($x, @a); I think it should say something like: Use of undefined value at foo line

Re: Optional binding

2005-03-06 Thread Yuval Kogman
On Sun, Mar 06, 2005 at 02:13:09 -0700, Luke Palmer wrote: > What is output: > > sub foo($x, ?$y, [EMAIL PROTECTED]) { > say "x = $x; y = $y; z = @z[]"; > } > > my @a = (1,2,3); > foo($x, @a); And is $a ==> foo $x; The same? -- () Yuval Kogman <[EMAIL PROTEC

Re: Optional binding

2005-03-06 Thread Brent 'Dax' Royal-Gordon
Luke Palmer <[EMAIL PROTECTED]> wrote: > What is output: > > sub foo($x, ?$y, [EMAIL PROTECTED]) { > say "x = $x; y = $y; z = @z[]"; > } > > my @a = (1,2,3); > foo($x, @a); IANALarry, but I'd think x = ($x's value); y = 1 2 3; z = The $y is implicitly typed Any, and

Optional binding

2005-03-06 Thread Luke Palmer
What is output: sub foo($x, ?$y, [EMAIL PROTECTED]) { say "x = $x; y = $y; z = @z[]"; } my @a = (1,2,3); foo($x, @a); Thanks, Luke