ulisp-esp icon indicating copy to clipboard operation
ulisp-esp copied to clipboard

Please provide an (UNWIND-PROTECT x) function

Open phmarek opened this issue 5 years ago • 3 comments

I'd like to have my ESP32 available via WIFI all the time. I've got a simple telnet REPL working; the one problem left is that some error (any error) breaks the Lisp REPL and returns to the serial console.

I'd imagine that UNWIND-PROTECT would set some variable to the current execution point (and croak if it's already set, to make it non-reentrable); error and error2 would check that variable, and when it's set store the current error in another variable (that can be queried from Lisp) and instead of doing the longjmp(exception, 1) they should restore the execution point to the saved one.

So my REPL could just run something like

(setf *last-error* nil)
(let ((result (unwind-protect (eval input))))
  (cond
    (*last-error*
      (princ "Error: " client)
      (princ *last-error* client))
    (t
      (princ result))))

phmarek avatar Feb 23 '19 18:02 phmarek

Sorry for the delay in replying. I agree that unwind-protect would be useful, but the action "restore the execution point to the saved one" is difficult because of the need to restore the state of the stack. I'll give it some more thought, but I suspect it will involve a major rewrite of uLisp.

technoblogy avatar Apr 11 '19 15:04 technoblogy

Still thinking about this!

technoblogy avatar Jun 24 '19 15:06 technoblogy

Whether it ends up in official uLisp or not, I found that @Goheeca and @m-g-r implemented (unwind-protect) and a few other error-related functions. See these two links:

  • https://github.com/Goheeca/redbear_duo-uLisp/commit/4894c13
  • http://forum.ulisp.com/t/error-handling-in-ulisp/691/7

You'll have to apply the patches yourself. I did on my uLisp, and it works great.

EDIT: I will note here that when I tried to use (error) it caused a Guru Meditation Error (i.e. a segfault), and so I had to replace it with a simpler (throwerrorstring) (my own creation; not a special form which I think was the problem).

dragoncoder047 avatar Aug 15 '22 01:08 dragoncoder047

Now included in uLisp Release 4.4.

technoblogy avatar Mar 29 '23 07:03 technoblogy