in reply to How implement AMB in perl?

Interesting article, thanks, I didn't know about amb before. As to your question how one would implement the function in perl, let me quote the aticle:

...we perform a depth-first search of the amb choice tree, and whenever we brush against failure, we backtrack to the most recent node of the tree that offers a further choice

In Perl, the function of the "choice tree" can be thought of as the function of the OP tree. That means, whenever amb would be called, it should investigate the caller and traverse the OP tree. The closest module I know that does similar things is Want module, which travels up the caller's OP tree. It would be really interesting to see if this approach works for amb.

Update: as to continuations, check out Coro.

Replies are listed 'Best First'.
Re^2: How implement AMB in perl?
by Enlil (Parson) on Apr 29, 2007 at 09:30 UTC
      That'd be also interesting indeed, except that regexes should operate on the OP-tree, not a string. Shouldn't be a too big problem with (??{}) and friends though.
        I tried hard to use a regex (??{}) solution for my Pentominos Solving Quine, but in a recursion scenario, there are some issues with re-entrancy which can cause (at least some versions of) perl's interpreter to crash.

        If you don't have to recurse, then by all means, any backtracking problem you can implement in the regex engine is fiendishly clever. Of course, "clever code" is for fun, not generally for maintainable code.

        --
        [ e d @ h a l l e y . c c ]