Nasser M. Abbasi wrote:
> But how do I set a time-out, and also how to I know if
> integrate finished due to time-out or not,
As I wrote, there is no official support for timeouts. But
when using sbcl as Lisp compiler the following seem to work.
We need Lisp support routines, say 'timeout.lisp':
;---------------<timeout.lisp start>----------------
(defun |do_timeout| (f ti)
(handler-case
(sb-ext:with-timeout ti (SPADCALL f))
(sb-ext:timeout (e)
(THROW '|trapSpadErrors| |$numericFailure|))
)
)
(defun |timed_eval| (f ti)
(CATCH '|trapSpadErrors| (cons 0 (|do_timeout| f ti))))
;---------------<timeout.lisp end>--------------
Then we need extra FriCAS wrapper, say 'timeout.input':
---------------<timeout.input start>---------------
do_timed_eval(f : () -> eI, t : Integer) : Union(eI, "failed") ==
timed_eval(f, t)$Lisp pretend Union(eI, "failed")
---------------<timeout.input end>------------------
Note the routine above works for any type, but we need to
specify one. So one has to declare eI to be appropriate
type. Below I use Expression(Integer), but you probably
want different type.
In the command line we do:
eI := Expression(Integer)
)read timeout.lisp
)read timeout.input
f0(): eI == 1
ff() : eI == (repeat true; 0)
Note: the fist command chooses type, assign here what is needed.
The last two lines above just define example functions.
After that we can do:
(9) -> do_timed_eval(ff, 3)
(9) "failed"
Type: Union("failed",...)
(10) -> do_timed_eval(f0, 3)
(10) 1
Type: Union(Expression(Integer),...)
So in case of timeout you get "failed" and otherwise normal result.
You can test which one you obtained by using 'case' construct:
x case "failed"
is true for "failed" branch of Union,
x case eI
is true for the other branch.
--
Waldek Hebisch
--
You received this message because you are subscribed to the Google Groups
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.