Talk:Amb: Difference between revisions

m
removed math markup
(comment on Amb semantics)
m (removed math markup)
Line 27:
Wouldn't it more sense just to call the task something like "nondeterministic choice" and leave it to the implementations to use whatever language feature works best for that? The SICP implenetation uses call/cc and side-effects, but to require a special operator ''amb'' for Prolog, where nondeterminism is in-built, is a bit silly. Python has generators. And it's equally silly in the Haskell example, where ''amb'' just reduces to the identity in the List-Monad. One could emulate the construction in the Continuation-and-State-Monad, but that would be even more silly :-) After all, the article "Replacing failure with a list of successes" was written long after SICP. The List-Monad construction also probably carries over more easily to other languages than call/cc. --[[User:Dirkt|Dirkt]] 02:22, 25 March 2008 (MDT)
 
What I think the first sentence is trying to say (and also the conventional meaning) is that Amb is a bottom-avoiding choice combinator. Suppose you have a function <math>f</math> that works fine for some inputs <math>x</math>, but crashes or fails to terminate for others. Similarly a function <math>g</math> works only for some limited set of inputs, not necessarily the same as <math>f</math>. Then <math>\mathrm{Amb}(f,g)</math> is a function that returns either <math>f(x)</math> or <math>g(x)</math> when given an input <math>x</math>, but is guaranteed (!) to choose the one that terminates correctly if one of them does and the other doesn't. Once you understand this definition, you'll realize that the only right way to implement Amb for arbitrary unknown functions <math>f</math> and <math>g</math> is by multi-threading or interleaving on some level, which is where the emphasis in this task belongs. (You can't get away with using only exception handlers unless you excludewant to neglect the possibility of non-termination.) Note that this semantics differs from non-deterministic choice. If <math>f</math> and <math>g</math> happen to have disjoint domains, it's completely deterministic.
 
--[[User:Sluggo|Sluggo]] 22:20, 6 September 2009 (UTC)
Anonymous user