ulisp-esp
ulisp-esp copied to clipboard
Please provide an (UNWIND-PROTECT x) function
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))))
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.
Still thinking about this!
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).
Now included in uLisp Release 4.4.