Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^3: Iterating over verbatim hash reference

by rubasov (Friar)
on Jan 22, 2010 at 12:31 UTC ( #818953=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Iterating over verbatim hash reference
in thread Iterating over verbatim hash reference

That duplication trick is really not nice, but I don't see a way how can this be avoided in perl5 (probably a wiser monk may shed some light on this).

Some other languages have nicer constructs for recursive anonymous functions without this trickery, look at a few examples at stackoverflow.com.

However I treated the challange of "eliminating named variables", more as a (math-like) challange of using functional programming concepts in perl5, rather than "how to achieve tha same results in real code".

update:
we have just traded the name of a hash for a name of a sub [...], so it's not a real gain
That's true for the particular code above, however think of this issue more generally. If we insist on retaining the sub identifier, that still has its advantages, because in lots of code, we traded lots of hash identifiers for one sub identifier.


Comment on Re^3: Iterating over verbatim hash reference
Re^4: Iterating over verbatim hash reference
by rovf (Priest) on Jan 22, 2010 at 14:02 UTC
    more as a (math-like) challange of using functional programming concepts
    I see it more like a challenge too. In functional programming, there is usually a concept employed known as Y combinator. The idea is very similar like yours (including the repetition of the code), but once you define this combinator, you can use it for producing anonymous recursive functions at will. In Haskell, for instance, it is builtin and called fix (finding the fixpoint of a recursion).

    http://en.wikipedia.org/wiki/Fixed_point_combinator

    http://www.ece.uc.edu/~franco/C511/html/Scheme/ycomb.html

    Sadly, I don't have any experience with this :-(
    -- 
    Ronald Fischer <ynnor@mm.st>

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (9)
As of 2014-10-25 16:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (145 votes), past polls