[Openmcl-devel] Catching Control C

Jon S. Anthony j-anthony at comcast.net
Mon Feb 1 06:47:17 PST 2010


On Sun, 2010-01-31 at 23:42 +0100, Waldek Hebisch wrote:

I'm not sure of the details of what you are trying to do, but a few
things come to mind that may help you along.

You don't need (or probably want) fricas-application and refining
ccl::top-level-function.  This stuff was changed to more accurately
reflect the concepts involved for getting app specific toplevels to
work/run in 1.3  It's much nicer now.

You shouldn't need *my-toplevel-function* either.  repl-function-name
should just return the name of your toplevel function (that's the
intent)

So, the basic idiom is something like:

(defclass fricas-development-system (ccl::lisp-development-system) ())

(defun my-toplevel () ...)

(defmethod repl-function-name ((a aria-application))
  'my-toplevel)

Then the machinery in ccl::toplevel-function will call your toplevel.

You may want to look at method application-error:

(defmethod application-error ((a fricas-development-system) condition
error-pointer)
 ...)

Something like the following may get you (close/closer) to where you
want to be:

In my-toplevel:

(loop
  (catch :fricas-main
    ...))

In application-error:

  ... ;; something or other
  (throw :fricas-main nil)
  ... ;; exit or something


/Jon

> Thanks for information.  I do not care if Clozure CL needs some extra
> threads for internal tasks.  I am affraid I can not simply call
> CCL::HOUSEKEEPING-LOOP because I want that after my main function
> exits control should go to normal Lisp toplevel.  Using your
> information I modified my program so that now Control C gives me
> Lisp debugger.  However, how can handle it in my main thread?
> 
> I produce exutable by loading code below and doing
> 
> (CCL::save-application "./app3" :PREPEND-KERNEL t
>                    :application-class 'fricas-application)
> 
> -------------<code below>--------------------
> 
> (defclass fricas-application (ccl::application) ())
> 
> (defvar *my-toplevel-function* nil)
> 
> (defclass fricas-development-system (ccl::lisp-development-system) ())
> 
> (defmethod repl-function-name ((a fricas-development-system))
>     #'(lambda ()
>          (funcall *my-toplevel-function*)
>          (ccl::listener-function)))
> 
> (defmethod ccl::toplevel-function ((app fricas-application) init-file)
>     (declare (ignore init-file))
>         (call-next-method) ; this is critical, but shouldn't be.
>         (let ((ap (make-instance 'fricas-development-system)))
>             (ccl::toplevel-function ap nil)))
> 
> (defun mini-repl()
>     (loop (print (eval (read)))))
> 
> (defun my-error-handler(c)
>     (format t "~a~&" c)
>     (quit))
> 
> (defun mini-repl2()
>   (let ((*debugger-hook*
>             (lambda (condition previous-handler)
>                 (format t "~a~&" c)
>                 (quit))
>        ))
>     (handler-bind ((error #'my-error-handler))
>        (mini-repl))))
> 
> (setf *my-toplevel-function* #'mini-repl2)
> 
> -- 
>                               Waldek Hebisch
> hebisch at math.uni.wroc.pl 
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel




More information about the Openmcl-devel mailing list