Only use one variable to store the unification environment in MATCHING
Fri Jan 15 08:49:26 UTC 2010 pix@kepibu.org
* Only use one variable to store the unification environment in MATCHING
Because of the way MATCHING expands, and what UNIFY* returns, each
(setf #:env (unify* ...))
call will do one of two things: it will set #:env to NIL or it will set #:env to
an ENVIRONMENT structure.
If #:env is set to NIL--the same value it entered the (setf) with!--the COND
will continue on to the next clause.
If #:env is set to an ENVIRONMENT structure, none of the remaining (setf)
clauses will be evaluated.
Thus, because the variable will only ever be set to a non-nil value once, this
should be perfectly safe.
diff -rN -u old-cl-unification-1/match-block.lisp new-cl-unification-1/match-block.lisp
--- old-cl-unification-1/match-block.lisp 2013-07-21 19:25:52.000000000 +0000
+++ new-cl-unification-1/match-block.lisp 2013-07-21 19:25:52.000000000 +0000
@@ -192,21 +192,16 @@
(match-clauses (delete default-clause match-clauses)) ; EQL
; test
; suffices.
- (match-clauses-env-vars (mapcar (lambda (mc)
- (declare (ignore mc))
- (gensym "UNIFICATION-ENV-")
- )
- match-clauses))
+ (env-var (gensym "UNIFICATION-ENV-"))
)
`(block ,matching-named
- (let ,match-clauses-env-vars
- (declare (dynamic-extent ,@match-clauses-env-vars))
- (cond ,@(mapcar (lambda (match-clause match-clause-env-var)
+ (let (,env-var)
+ (declare (dynamic-extent ,env-var))
+ (cond ,@(mapcar (lambda (match-clause)
(build-match-clause match-clause
- match-clause-env-var))
- match-clauses
- match-clauses-env-vars)
+ env-var))
+ match-clauses)
(,errorp
(error 'unification-non-exhaustive
:format-control "Non exhaustive matching."))