1 ;; stopme command, only for sbcl
4 ;; stopme and time_constrained are the same except that
5 ;; time_constrained, in case of timeout simply returns
6 ;; the expression Aborted.
7 ;; stopme gives a message, and returns it. The message contains the unevaluated expr.
8 ;; There are too many other variants possible to cover them all.
9 ;; You may want a slightly different behavior. e.g. return unevaluated expr only.
10 ;; (Mathematica returns "$Aborted" for timeout.)
13 (defmspec $stopme
(args) ;; usage: stopme (do x:x+1, 2) ; stops infinite loop after 2 sec
14 (let* ((evalme(cadr args
)) ; not evaluated !
15 (timelimit (meval (caddr args
))) ; evaluate the time limit
16 (v (sb-ext::make-timer
;; the timer program
18 (let ((msg `((mtext) ,evalme
" timed out after " ,timelimit
" seconds")))
20 (throw 'stopme msg
))))))
23 (sb-ext::schedule-timer v timelimit
)
25 (sb-ext::unschedule-timer v
)) ))))
28 (defmspec $time_constrained
(args) ;; usage: stopme (do x:x+1, 2) ; stops infinite loop after 2 sec
29 (let* ((evalme(cadr args
)) ; not evaluated !
30 (timelimit (meval (caddr args
))) ; evaluate the time limit
31 (v (sb-ext::make-timer
;; the timer program
32 (lambda()(throw 'stopme
'$Aborted
33 ;;evalme ;; just return unevaluated.
37 (sb-ext::schedule-timer v timelimit
)
39 (sb-ext::unschedule-timer v
)) ))))
41 #-sbcl
(format t
"~%time_constrained and stopme
42 are currently unimplemented
44 Available in sbcl versions of Maxima. ~%")