Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!zaphod.mps.ohio-state.edu!think!barmar From: barmar@think.com (Barry Margolin) Newsgroups: comp.lang.lisp Subject: Re: Question about Macros (Common Lisp) Message-ID: <33613@news.Think.COM> Date: 3 Feb 90 05:15:42 GMT References: <31480@shemp.CS.UCLA.EDU> Sender: news@Think.COM Distribution: usa Organization: Thinking Machines Corporation, Cambridge MA, USA Lines: 32 In article <31480@shemp.CS.UCLA.EDU> srt@maui.cs.ucla.edu (Scott Turner) writes: >What's the solution? I have to delay the de-reference of the symbol until >the macro is actually expanded. I came up with this: > `(setf (structure-test foo) > #'(lambda (,(intern "*SPEC*")) ,@test-part)) >Which (surprise!) works, but which I find pretty ugly and disgusting. >So, is there a better way to do this? Or is my whole approach wrong-minded? I have a couple of ideas. 1. Require the users of your package to (import 'rule::*spec*). 2. Don't automatically bind the variable *spec*. Allow the macro user to specify his variable. I think this is a good idea regardless of the package problem. If you need the special variable bound in order to communicate among internal routines of the Rule system, bind it using LET and then pass the value to the functions created by the macro. The only problem with this is that if the user writes (setq ) it won't change *spec*. Symbolics Genera has some facilities that work like your macro; for instance, their ADVISE macro uses the variables ARGLIST and VALUES similarly. Their solution is a variant on #1 above -- these symbols are external in the COMMON-LISP package (VALUES is a CL function name, and ARGLIST is a CL declaration name), and most user programs are in packages that inherit from COMMON-LISP, so they get the right symbol. However, I wouldn't suggest this solution for your problem. -- Barry Margolin, Thinking Machines Corp. barmar@think.com {uunet,harvard}!think!barmar