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

I'm sure you don't want to use this in real code
Except, maybe, on a day I am very angry to my co-workers :-P I really appreciate your elaborate idea (wonderful analysis!), but it bites us from behind: By the replication step in your transformation, you introduce two anonymous subs which are exactly identical, so being good programmers, we will of course give a name to the sub and end up with only one copy of the subroutine; but as soon we do this, we have just traded the name of a hash for a name of a sub (and indeed, this can be done with any other data element as well), so it's not a real gain...

-- 
Ronald Fischer <ynnor@mm.st>

Replies are listed 'Best First'.
Re^3: Iterating over verbatim hash reference
by rubasov (Friar) on Jan 22, 2010 at 12:31 UTC

    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.
      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>