home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.lisp
- Path: sparky!uunet!caen!hellgate.utah.edu!hellgate!moore
- From: moore@cs.utah.edu (Tim Moore)
- Subject: Re: Can I use EVAL?
- Message-ID: <MOORE.92Aug25153642@defmacro.cs.utah.edu>
- Followup-To: comp.lang.lisp
- In-reply-to: danny@farallon.com's message of 25 Aug 92 19:52:35 GMT
- Organization: University of Utah CS Dept
- References: <danny-250892143222@danny.farallon.com>
- Date: 25 Aug 92 15:36:42
- Lines: 45
-
- In article <danny-250892143222@danny.farallon.com> danny@farallon.com (Danny Brewer) writes:
-
- ;;; Now compile the pattern into a LAMBDA using compiling matcher
-
- ? (Compile-Match '(a ?x c))
- (LAMBDA (DATUM ...) [...a bunch of code deleted...] )
-
- ? (SETF *p* *) ; save pattern code in a variable
- ? (SETF *d* '(a b c)) ; set datum variable
-
- Now that I've got the LAMBDA in the variable *p*, how can I do
- anything with it? I can't FUNCALL or APPLY it. But I can
- use a really ugly EVAL as follows:
-
- ? (EVAL `(,*p* ',*d*))
- ((?X . B))
-
- This works okay, but yucko!
-
- (eval `#',*p*) will return a function. In cltl2 lisps, you can coerce
- the lambda expression returned by compile-match to a function:
-
- (coerce *p* 'function)
-
- These solutions use eval explicitly or implicitly, but that's OK. eval
- was made for this sort of thing. If you are translating little
- languages to lisp code, the prohibition against using eval breaks
- down.
-
- You could compile the lambda expression:
- (compile nil *p*)
-
-
- Alternatively, you could think about defining your patterns in a
- declarative manner so that the lambda expressions will be dealt with
- at compile or load time:
-
- (defmacro defpattern (pattern)
- `(eval-when (:compile-toplevel :execute)
- (add-pattern-to-db ,pattern #',(compile-match pattern))))
-
- --
- Tim Moore moore@cs.utah.edu {bellcore,hplabs}!utah-cs!moore
- "Wind in my hair - Shifting and drifting - Mechanical music - Adrenaline surge"
- - Rush
-