home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / lisp / 2333 < prev    next >
Encoding:
Text File  |  1992-08-29  |  1.9 KB  |  47 lines

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