Arc Forumnew | comments | leaders | submitlogin
Nondeterminism (On Lisp style) in Arc
9 points by cooldude127 6151 days ago | discuss
I took a very small amount of time to translate On Lisp's scheme implementation of choose and fail into Arc. It is quite elegant, I must say. Here it is:

  (= paths* ()
     failsym* '@)

  (def choose (choices)
    (if (no choices)
        (fail)
        (ccc (fn (cc)
               (push (fn ()
                       (cc (choose (cdr choices))))
                     paths*)
               (car choices)))))

  (= fail nil)

  (ccc (fn (cc)
         (= fail
            (fn ()
              (if (no paths*)
                  (cc failsym*)
                  ((pop paths*)))))))
One problem: instead of returning the failsym when all possibilities fail, it gives this error:

  Error: "read-char: input port is closed"
Not sure what that's all about.