What I have in mind is something like:
(run (long-calculation vars) time-limit)
which returns the result of (long-calculation vars)
or nil
if time-limit
is reached.
If you could find an implementation for the amb
operator, then you could do something like this:
(defmacro run (comp time-limit)
`(amb comp
(progn (delay ,time-limit)
nil)))
Be careful not to mistake this with the McCarthy amb
operator. amb
should evaluate both its arguments in separate threads and pick whichever finishes first. For example, in Haskell, it's described in Data.Unamb.
I would suggest using bordeaux-threads, spawning a thread for the computation, and if it doesn't return by the timer, reaping the thread and returning nil.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With