lips
lips copied to clipboard
try..catch is broken
Here is an example:
(define (until-zero fn lst)
(try (for-each (lambda (x)
(if (zero? x)
(throw 'ZONK)
(fn x)))
lst)
(catch (e)
(print "err")
(print e))))
(print "----")
(until-zero print '(1 2 0 3 4))
(print "----")
(until-zero print '(0 1 2 3 4))
it prints:
----
1
2
err
ZONK
3
4
----
err
ZONK
1
2
3
4
another issue is that when throws is called it keep adding Error: so last error is:
Error: Error: Error: Error: ZONK
This is a fundametal error, exceptions don't stop the execution:
(try
(begin
(print 'foo)
(print 'bar)
(throw 'ZONK)
(print 'baz)
(print 'quux))
(catch (e)
(print e)))
;; ==> foo
;; ==> bar
;; ==> ZONK
;; ==> baz
;; ==> quux
Probably because if real exceptions happen it's bubble up in evaluate. Maybe silent.error needs to be introduced like in R shiny framework. Or we need to wait for continuations.
Another idea is to create a stack of error handlers and handle errors by hand instead of using functions. Maybe try..catch needs to be in the core of evaluate (but It would be nice if this could be just macro).
Does Lips implement (guard ...) from R7RS?
@lassik No, but It probably can be implemented with try..catch, it will be simple symbol swapping.
I think that this is a good time to start adding continuations.
Basic code works:
(try
(begin
(print 'foo)
(print 'bar)
(throw 'ZONK)
(print 'baz)
(print 'quux))
(catch (e)
(print e)))
But the for-each example is still not fixed.