in reply to Re: Syntactic sugar for tail call optimizations
in thread Syntactic sugar for tail call optimizations

> Of course, as soon as the recursive sub starts doing anything remotely requiring recursion your 'pattern' falls apart like bad knitting.

And of course you can easily provide an example proving your polemic assertion...

Cheers Rolf

  • Comment on Re^2: Syntactic sugar for tail call optimizations

Replies are listed 'Best First'.
Re^3: Syntactic sugar for tail call optimizations
by BrowserUk (Patriarch) on May 27, 2011 at 15:50 UTC
    And of course you can easily provide an example proving your polemic assertion...

    Of course:

    use enum qw[ CODE GRAPH START PATH SEEN ]; sub _pathsFrom { return $_[CODE]->( @{ $_[PATH] }, $_[START] ) unless exists $_[GRAPH]->{ $_[START] }; for ( @{ $_[GRAPH]->{ $_[START] } } ) { if( exists $_[SEEN]->{ $_[START] . "-$_" } ) { return $_[CODE]->( @{ $_[PATH] }, $_[START] ); } else { _pathsFrom( @_[ CODE, GRAPH ], $_, [ @{ $_[PATH] }, $_[START] ], { %{ $_[SEEN] }, $_[START] . "-$_", undef } ); } } } sub pathsFrom(&@) { _pathsFrom( @_, [], {} ) }

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Ah I see a trivial example already remotely requiring recursion

      without sample data for your spontaneous example I can't test, but the following should do.

      use enum qw[ CODE GRAPH START PATH SEEN ]; sub _pathsFrom { _PATHSFROM: { return $_[CODE]->( @{ $_[PATH] }, $_[START] ) unless exists $_[GRAPH]->{ $_[START] }; for ( @{ $_[GRAPH]->{ $_[START] } } ) { if ( exists $_[SEEN]->{ $_[START] . "-$_" } ) { return $_[CODE]->( @{ $_[PATH] }, $_[START] ); } else { @_=( @_[ CODE, GRAPH ], $_, [ @{ $_[PATH] }, $_[START] ], { %{ $_[SEEN] }, $_[START] . "-$_", undef } ); redo _PATHSFROM; } } } }

      If not, enlighten us!

      UPDATE(18:16 CEST): This thread is about implementating tail call recursions, thanks for trolling with a graph-search recursion which isn't tail code.

      Cheers Rolf

        This thread is about implementating tail call recursions, thanks for trolling with a graph-search recursion which isn't tail code.

        Oh, sorry. I thought you'd know that every recursive algorithm can be made into a tail-recursive one(*).

        So you see there is no trolling and no polemic; just an example, as you requested, that you don't know how to handle.

        And, BTW, one disproves your flimsily expounded theory.

        * All you need to do is implement the CPS transform.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.