[Israel.pm] Fwd: [Telux] Next Meeting: "High-Level Programming Concepts Using Perl 6" on 22-March

Mikhael Goikhman migo at homemail.com
Sat Mar 14 14:55:28 PDT 2009


On 14 Mar 2009 23:17:26 +0200, Evgeny wrote:
> 
> So the block (sub) works without the word "sub" only if it is the first
> parameter?

Yes. My second answer was for block meaning closure, not about the
syntactic sugar.

Actually having two pairs of {} together is kind of possible, but
does not do what you want:

  sub run (&$$) { $_[0]->(); print %{$_[1]}, %{$_[2]} }

  run { print "ok" } { key => "value" }, { 1 .. 9 };

I didn't see your actual DSL requirements. As I also mentioned, possibly
this syntax may work for you (try to figure out the needed prototypes):

  apply { one-thing } on { another-thing };

Regards,
Mikhael.

> On Sat, Mar 14, 2009 at 10:40 PM, Mikhael Goikhman <migo at homemail.com>
> > wrote: On 14 Mar 2009 19:20:05 +0200, Evgeny wrote:
> >>
> >> Actually, in ruby I can have a method that accepts multiple blocks.
> >> Blocks don't HAVE to come as the last argument.   def (&first_block,
> >> &second_block) will work as well.
> >
> > The same syntax works in Perl. We just spoke about DSL (syntactic
> > sugar).
> >
> > Moreover, in Perl you can pass any number of anonymous functions
> > (closures) defined inline, something that is for example impossible
> > in Python by design.
> >
> >  run(sub { do something; do well }, sub { do something else });
> >
> >> But in perl, I tried to do the same - by replacing sm(&$) to be
> >> sm($&) - but it does not work. So does that mean that in perl I
> >> can't have the block where ever I want, and pass it as the last
> >> argument? Why?
> >
> > Nope, this is incorrect. I demonstrated this in the previous message:
> >
> >  Given /regular-expression-here/, sub { some code here };
> >
> > This works too (no need for parentheses if you specify prototypes):
> >
> >  run $first_arg, sub { "second" }, 3, sub { "forth" };
> >
> > Regards,
> > Mikhael.

-- 
perl -e 'print+chr(64+hex)for+split//,d9b815c07f9b8d1e'



More information about the Perl mailing list