4 ms·
Given the existence of exception handling, I would rather apply the pattern: ;; Plain old ANSI Lisp (let* ((x (or (foo) (error "...")))) (y (o
by kazinator 10y ago
Given the existence of exception handling, I would rather apply the pattern:
;; Plain old ANSI Lisp
(let* ((x (or (foo) (error "..."))))
(y (or (bar x) (error "bar ..."))
...)
body)
I mean, if, in the end, we are going to "error out", rather than just forward-propagate `nil`.
If we are going to just propagate `nil`, then if we have an `iflet` that tests the last variable, we can do:
(iflet ((x (expr))
(y (if x (bar x))
(z (if y (foo x y))) ;; z is tested by iflet
...)
it's just a bit verbose. That can be condensed with a simpler macro that doesn't have the err stuff.
- sdegutis 10y agoYour solution doesn't short-circuit when any of the calls fail. It relies on (error) throwing some kind of exception to interrupt control flow and prevent the following lines from executing.
- kazinator 10y agoYes; I'm using ANSI CL syntax/semantics. error denotes cl:error which can in fact be relied upon to throw. That's what I mean by "given the existence of exception handling ...". Substitute your favorite dialect's error thrower.