Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: recursive anonymous subroutines

by Zaxo (Archbishop)
on Apr 06, 2006 at 20:05 UTC ( #541713=note: print w/ replies, xml ) Need Help??


in reply to recursive anonymous subroutines

No.

That's too bad, too. I've occasionally wanted something like that myself.

What semantics should that have, do you think? A magical local variable which points to the current block? [Added]: Or extend redo to apply to code blocks?

After Compline,
Zaxo


Comment on Re: recursive anonymous subroutines
Re^2: recursive anonymous subroutines
by ambrus (Abbot) on Apr 06, 2006 at 20:27 UTC

    The J language has something like that, a magical operator called $: which always refers to the innermost verb it is used at.

    However, I don't like that, and don't think it would be a good idea for perl. I'd rather like something like (one form of) the let macro in scheme. The equivalent to this would be something like this in perl: the hypothetical let NAME { BODY } ARGS could be equivalent to do { my sub NAME { BODY }; NAME(ARGS); }, where you can call NAME in the BODY too. Except we'd need a different name instead of let.

    Update: redo wouldn't help. That only works if you have tail recursion. Redo doesn't return.

      the whole point is not to name the beast. I like the idea of a $thingy :
      (sub {... $thingy->(...) ... )->(args);
      would suit me just fine. Oh well. I can live without it.

      Thanks again.
        It's been done.
        use Sub::Recursive; recursive { ... $REC->(...) ... }->(args)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://541713]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2014-07-28 23:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (210 votes), past polls