[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

macrolet



When I read the explanation for macrolet on page 114, Cltl, I had a few
problems with the 'clear' example:

(defun foo (x flag)
  (macrolet ((fudge (z)
		;The parameters x and flag are not accessible
		;at this point; a reference to flag would be to
		;the global variable of that name.
		`(if flag (* ,z ,z) ,z)))
	;The parameters x and flag are accessible here.
	(+ x
	   (fudge x)
	   (fudge (+ x 1)))))

It seems that while this is a valid example, it does not emphasize the
point that is trying to be made.  While 'fudge' is being defined foo's
flag is not accessible, but since flag is quoted inside of fudge, by
the time that the body of the macrolet is run, i.e., in (+ x ...),
flag is accessible.  Therefore if I run

(setq flag t) ==> t
(foo 10 nil) ==> 31 (since flag is taken as nil).

A more illustrative example might be to change the body of fudge to:

`(if ,flag (* ,z ,z) ,z)	; Evaluate flag within macro expansion

Now, by running

(setq flag t) ==> t
(foo 10 nil) ==> 231 (since flag is taken as t).

Elia Weixelbaum