home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!haven.umd.edu!darwin.sura.net!jvnc.net!yale.edu!think.com!barmar
- From: barmar@think.com (Barry Margolin)
- Newsgroups: comp.lang.lisp
- Subject: Re: Can I use EVAL?
- Date: 28 Aug 1992 21:11:27 GMT
- Organization: Thinking Machines Corporation, Cambridge MA, USA
- Lines: 35
- Message-ID: <17m4pvINNg2a@early-bird.think.com>
- References: <danny-250892143222@danny.farallon.com> <MOORE.92Aug25153642@defmacro.cs.utah.edu> <danny-280892103325@danny.farallon.com>
- NNTP-Posting-Host: telecaster.think.com
-
- In article <danny-280892103325@danny.farallon.com> danny@farallon.com (Danny Brewer) writes:
- >Other pattern directive examples would be:
- ...
- > (?:* ?items (LAMBDA (items) (SUBSETP (INTERSECTION items *x*) *y*)))
- >
- >The last example would match some items which when intersected with
- >the special variable *x* are a subset of special variable *y*.
-
- I suggest that you require the user to supply the actual function object in
- that case. He can do this by using backquote to construct the pattern that
- he supplies to MATCH:
-
- (match `((?:* ?items ,#'(lambda (items) (subsetp intersection items *x*) *y*)))
- data)
-
- Besides solving your problem of having to use EVAL or COMPILE to execute
- it, it also allows the user to supply a local function (i.e. one defined
- using FLET or LABELS), an expression that evaluates to a function, or a
- lexical closure, e.g.
-
- (defun example (data predicate)
- (flet ((local-predicate (items) (every #'numberp items)))
- (match `((?:* ?x ,predicate) (?:* ?y ,#'local-predicate)
- (?:* ?z ,#'(lambda (items) (member (car (last items)) '(a b c)))))
- data)))
-
- In all these cases, you can use FUNCTIONP to detect that the third element
- of the list is a function (note, however, that CLtL1 specified that
- FUNCTIONP is true for all symbols, even if they don't have function
- bindings, so you should check this case after most others).
- --
- Barry Margolin
- System Manager, Thinking Machines Corp.
-
- barmar@think.com {uunet,harvard}!think!barmar
-