Arc Forumnew | comments | leaders | submitlogin
3 points by absz 6069 days ago | link | parent

I think this doesn't quite work:

  arc> (amb 1 2)
  1
  arc> (amb (fail))
  2
  arc> (amb (fail))
  Error: "no more choices left"
My understanding is that when one leaves an amb, one can't use fail to return to it. Or am I supposed to be able to do this?


2 points by rincewind 6069 days ago | link

I think this is supposed to work.

From "Teach yourself Scheme in Fixnum Days":

In particular, amb is required to return a value if at least one its subexpressions converges, ie, doesn't fail. Thus,

   (amb 1 (amb))

 and
   
   (amb (amb) 1)

 both return 1.
http://www.ccs.neu.edu/home/dorai/t-y-scheme/t-y-scheme-Z-H-...

-----

1 point by absz 6068 days ago | link

That doesn't actually address my concern, but this (from the same page) does:

  (if (amb #f #t)
    1
    (amb))
This has to force the first amb to return #t, or the whole expression would fail. I still find it somewhat odd, though, that I can (fail) on the next line, but I suppose there's not a better way to handle it; after all, that's probably just because the interpreter is sequential.

-----