guicho271828 / trivia

Pattern Matcher Compatible with Optima
Other
332 stars 22 forks source link

Patterns with quote broken on Allegro #81

Closed ruricolist closed 7 years ago

ruricolist commented 7 years ago
CG-USER(3): (trivia:match 'x ('x t))
Error: attempt to call `NIL' which is an undefined function.
[condition type: UNDEFINED-FUNCTION]

The bug is in the expansion, not the macro itself.

guicho271828 commented 7 years ago

Thanks, fixed. This kind of bug always bites me... Variables in dolist are not lexically bound.

(let (acc)
        (dolist (s '(a b))
          (push (lambda () `(,s)) acc))
        (dolist (fn acc)
          (print (funcall fn))))
;; -> (NIL) 
;; -> (NIL) 
guicho271828 commented 7 years ago

On SBCL this does not happen. Surprisingly, this is acutally implementation-dependent. http://clhs.lisp.se/Body/m_dolist.htm

It is implementation-dependent whether dolist establishes a new binding of var on each iteration or whether it establishes a binding for var once at the beginning and then assigns it on any subsequent iterations.