Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!psuvax1!brutus.cs.uiuc.edu!usc!ucla-cs!srt From: srt@maui.cs.ucla.edu (Scott Turner) Newsgroups: comp.lang.lisp Subject: Question about Macros (Common Lisp) Message-ID: <31480@shemp.CS.UCLA.EDU> Date: 2 Feb 90 22:41:05 GMT Sender: news@CS.UCLA.EDU Reply-To: srt@maui.cs.ucla.edu (Scott Turner) Distribution: usa Organization: UCLA Computer Science Department Lines: 47 [Using Lucid Common Lisp on an Apollo Workstation.] I'm trying to build a macro to create ``rules''. A rule has some named components which get turned into lambdas and then later apply-ed by an interpreter. So, for example: (rule:define a-rule-name (test (eql *spec* 'hyper)) (action (cons *spec* 'foo))) In this example, "*spec*" is a parameter that will be passed in to each of the various parts when executed. For example, test gets turned into: (lambda (*spec*) (eql *spec* 'hyper)) To do this, I write a simple defmacro, the important part of which looks like this: `(setf (structure-test foo) #'(lambda (*spec*) ,@test-part)) Let's say that I define this macro in the RULE package. Later on, I go to use this in the USER package, and looking at the macro-expansion I see this: (lambda (rule::*spec*) (eql *spec* 'hyper)) Not what I expected. What's happened? Well, during the reading of the list that forms the backquote structure in my macro, the reader found "*spec*" and turned that into an atom in the RULE package, hence rule::*spec*. 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? Scott R. Turner UCLA Computer Science "If you act like a dumbshit, they'll treat you like an equal." Domain: srt@cs.ucla.edu