Arc Forumnew | comments | leaders | submitlogin
2 points by almkglor 6069 days ago | link | parent

In order to allow using amb in multiple threads (Anarki only!):

  (def getcc ()
    ccc.idfn)

  (= amb-stack* (thread-local))
  (= (amb-stack*) nil)

  (def fail ()
    (aif (amb-stack*) ((pop (amb-stack*)) nil) (err "no more choices left")))

  (mac amb vals
    ; use w/uniq !!
    (w/uniq return
      `(point ,return
        ,@(map
           [idfn `(aif (getcc) (do (push it (amb-stack*)) (,return ,_))) ] vals)
        (fail))))