Re: Playing with protos and phasers
While {*} is only useful in a proto, the compiler detects it no matter where you write it. > my $block = {*}; ===SORRY!=== Error while compiling: {*} may only appear in proto at line 2 --> ⏏ On Thu, Jun 25, 2020 at 3:48 PM Fernando Santagata < nando.santag...@gmail.com> wrote: > On Thu, Jun 25, 2020 at 8:10 PM Brad Gilbert wrote: > >> {*} is specially handled by the compiler as a term. >> > > Thank you! > > I guess that handling is peculiar to proto, and maybe it's worth > documenting it. > > -- > Fernando Santagata >
Re: Playing with protos and phasers
On Thu, Jun 25, 2020 at 8:10 PM Brad Gilbert wrote: > {*} is specially handled by the compiler as a term. > Thank you! I guess that handling is peculiar to proto, and maybe it's worth documenting it. -- Fernando Santagata
Re: Playing with protos and phasers
{*} is specially handled by the compiler as a term. Let's say you have a class named Foo: class Foo {…} You wouldn't expect to be able to use it like this: F o o.new() It is the same thing with {*}. The only difference is that {*} is meant to look like a Block { } combined with a Whatever *. It was meant to be both visually distinctive, and visually similar to how you might think about it. --- If you were allowed to add spaces to the {*} term, it would be annoying if you wanted to create a lambda that returned a Whatever. my $block = { * }; say $block.() ~~ Whatever; # True. On Thu, Jun 25, 2020 at 2:47 AM Fernando Santagata < nando.santag...@gmail.com> wrote: > Hi *, > I was trying to see if one can delegate phasers to a proto, like this: > > proto sub foo(|) { > ENTER { say 'In' } > LEAVE { say 'Out' } > {*} > } > multi sub foo(Int $a) { > $a > } > multi sub foo(Str $a) { > $a > } > > say foo(1); > say foo('hello'); > > Yes indeed, it outputs: > > In > Out > 1 > In > Out > hello > > But at first it didn't work, because I added a space on both sides of the > '*': > > proto sub foo(|) { > ENTER { say 'In' } > LEAVE { say 'Out' } > { * } > } > > It outputs: > > In > Out > * > In > Out > * > > If I add a return: > > proto sub foo(|) { > ENTER { say 'In' } > LEAVE { say 'Out' } > return { * } > } > > it outputs: > > In > Out > -> ;; $_? is raw = OUTER::<$_> { #`(Block|94038346387904) ... } > In > Out > -> ;; $_? is raw = OUTER::<$_> { #`(Block|94038346388120) ... } > > Why are spaces significant in this case? > > If this behavior is intentional, can this be a trap worth being documented? > > -- > Fernando Santagata >
Playing with protos and phasers
Hi *, I was trying to see if one can delegate phasers to a proto, like this: proto sub foo(|) { ENTER { say 'In' } LEAVE { say 'Out' } {*} } multi sub foo(Int $a) { $a } multi sub foo(Str $a) { $a } say foo(1); say foo('hello'); Yes indeed, it outputs: In Out 1 In Out hello But at first it didn't work, because I added a space on both sides of the '*': proto sub foo(|) { ENTER { say 'In' } LEAVE { say 'Out' } { * } } It outputs: In Out * In Out * If I add a return: proto sub foo(|) { ENTER { say 'In' } LEAVE { say 'Out' } return { * } } it outputs: In Out -> ;; $_? is raw = OUTER::<$_> { #`(Block|94038346387904) ... } In Out -> ;; $_? is raw = OUTER::<$_> { #`(Block|94038346388120) ... } Why are spaces significant in this case? If this behavior is intentional, can this be a trap worth being documented? -- Fernando Santagata