You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I just noticed a fairly significant difference between how if-let* and -if-let* handle binding in the ELSE clause:
(if-let* ((a 'a)
(b nil)
(c 'c)
(d 'd))
t
(list:a a :b b :c c :d d)) ;; => (:a a :b nil :c nil :d nil)
(-if-let* ((a 'a)
(b nil)
(c 'c)
(d 'd))
t
(list:a a :b b :c c :d d)) ;; => Debugger entered--Lisp error: (void-variable c)
You might think that this isn't important, but if the ELSE clause contains (if (and b d) ...), and b was nil, b will be defined, but d will be undefined, and it will raise an error.
I think this should probably be fixed to always bind all variables in the ELSE clause.
The text was updated successfully, but these errors were encountered:
if-let has a pretty clever way to do this... it expands to
(let*
((a
(andt'a))
(b
(and a nil))
(c
(and b 'c))
(d
(and c 'd)))
(if d t
(list:a a :b b :c c :d d)))
whereas -if-let expands to
(let
((--dash-source-289--
(b nil)))
(if --dash-source-289--
(let
((a
(pop --dash-source-289--)))
(if a
(let
((--dash-source-290--
(car --dash-source-289--)))
(if --dash-source-290--
(let
('(pop --dash-source-290--))
(ifquote
(let
((a
(car --dash-source-290--)))
(if a t
(list:a a :b b :c c :d d)))
(list:a a :b b :c c :d d)))
(list:a a :b b :c c :d d)))
(list:a a :b b :c c :d d)))
(list:a a :b b :c c :d d)))
The macroexpansion should be comparing -if-let* instead of -if-let - the latter only supports a single (VAR VAL) binding.
So it's actually treating (a (quote a)) as the match form, (b nil) as the value, and discarding the rest of the list (note that c and d don't show up in the macroexpansion.
Not that the actual expansion is much better:
(macroexpand'(-if-let* ((a 'a)
(b nil)
(c 'c)
(d 'd))
t
(list:a a :b b :c c :d d)))
;; =>
(let ((a 'a))
(if a
(let ((b nil))
(if b
(let ((c 'c))
(if c
(let ((d 'd))
(if d t
(list:a a :b b :c c :d d)))
(list:a a :b b :c c :d d)))
(list:a a :b b :c c :d d)))
(list:a a :b b :c c :d d)))
I just noticed a fairly significant difference between how
if-let*
and-if-let*
handle binding in the ELSE clause:You might think that this isn't important, but if the ELSE clause contains
(if (and b d) ...)
, andb
was nil,b
will be defined, butd
will be undefined, and it will raise an error.I think this should probably be fixed to always bind all variables in the ELSE clause.
The text was updated successfully, but these errors were encountered: