IRC channel logs

2025-04-16.log

back to list of logs

<lechner>old / thanks!
<lechner>Hi, what's a concise and pretty way to print exceptions for the user, please?
<ArneBab>lechner: I only know a non-concise way with (with-exception-handler (λ (e) (format #t "must be number, is ~S.\n" input) #f) (λ () (+ 5 input)) #:unwind? #t)) ;; #t: continue #f: stop
<meaty>Is there a way to have the guile repl ask for a value upon hitting an undefined symbol, the way common lisp does
<old>lechner: print-exception
<old>(print-exception (current-error-port) #f (exception-kind exn) (exception-args exn))
<lechner>old / thanks, that's great! I found it in NEWS
<lechner>mwette / Hi, do you have a convention for naming cdata objects vs their unboxed Guile equivalents?
<lechner>Hi, do I have to use make-exception-from-throw in order to get an exception-kind other than %exception if that's what I need in order to define a custom exception-printer?
<old>lechner: no. (raise-exception (make-exception ...)) should work
<old>you can also lookup the compound expections and do a pretty-print like you want
<lechner>old / okay thanks, but how do I define a printer for my custom exception, please? https://bpa.st/E4BA
<lechner>i needed it because it is part of the API. Some exceptions have to be caught and evaluated according to 'status' which I could not reliably get from other exception types
<old>lechner: (set-exception-printer! '%exception exception-printer)
<old>Note that this is a global printer
<lechner>old / okay, but shouldn't it be '%pam-exception or something like that?
<old>nope
<lechner>don't the different types have different printers?
<old>exception-kind returns %exception for every exception derived from &exception
<lechner>right
<old>but you could do a dispatching if you want
<old>it would work not nicely
<old>because it's global
<lechner>is that printer mechanism well-designed?
<lechner>or should I use make-exception-from-throw instead?
<lechner>ACTION is trying to find the code reference
<lechner>actually, it's right in the manual
<lechner>also, how may I pretty-print compound exceptions, please?
<lechner>that should also happen automatically, i think
<old>I would say that the exception printer mechanism is not really great at the moment
<old>but you could roll your own if you want
<old>and override the core binding so that every modules use your version
<lechner>old / okay, thanks! i'll do that. I already use the exception-predicate to allow &quit-exceptions for signal handlers. maybe i'll even send in the result if it's worthwhile. do you have a starting point, for example for &compound-exceptions?
<old>unfortunatelly no. I've always just used `print-exception' with `exception-kind' and `exception-args'
<old>Guile exceptions is a big can of worms due to the legacy API throw/catch that must remained compatible with the new compound exceptions
<old>and I don't want to mess with it :-)
<lechner>i won't either. i just want to print them
<lechner>old / thank you for all your help over the last few day, by the way
<lechner>that line really deserved an exclamation mark
<old>my pleasure :-)
<lechner>Hi, does this (untested) look like something useful for exception in Guile? https://bpa.st/25KA
<lechner>Hi, is it bad form to (use-modules) in a Macro?
<lechner>what if it's srfi-1?
<dthompson>yeah it's a bad idea
<lechner>dthompson / okay, thanks!
<dthompson>yw :)
<lechner>Hi, looking at 'any' in SRFI-1, could it be replaced by (not (not (or ...)))
<dthompson>no, as 'any' operates on a list
<lechner>(not (not (apply or LIST))) ?
<dthompson>'or' is syntax
<dthompson>and 'any' applies a custom predicate, not just testing if the elements are #f or something else
<lechner>whoops, that's different from Perl. thanks!
<lechner>or maybe it isn't