[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Common Lisp like feature expressions
From: |
Stefan Monnier |
Subject: |
Re: Common Lisp like feature expressions |
Date: |
Mon, 27 Dec 2010 20:01:02 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) |
> (defun eval-feature-expression (form)
> (cond
> ((atom form) (featurep form nil))
> ((eq (car form) 'not)
> (not (eval-feature-expression (cadr form))))
> ((eq (car form) 'and)
> (if (not (cdr form))
> t
> (and (eval-feature-expression (cadr form))
> (eval-feature-expression (cons 'and (cddr form))))))
> ((eq (car form) 'or)
> (if (not (cdr form))
> nil
> (or (eval-feature-expression (cadr form))
> (eval-feature-expression (cons 'or (cddr form))))))
> (t (error "Invalid feature expression: %s" form))))
Just for fun, here's a version using pcase:
(defun eval-feature-expression (form)
(pcase form
((pred atom) (featurep form nil))
(`(not ,x) (not (eval-feature-expression x)))
(`(and) t)
(`(and ,form1 . ,forms)
(and (eval-feature-expression form1)
(eval-feature-expression (cons 'and forms))))
(`(or) nil)
(`(or ,form1 . ,forms)
(or (eval-feature-expression form1)
(eval-feature-expression (cons 'or forms))))
(t (error "Invalid feature expression: %s" form)))))
-- Stefan
- Re: How and when to use GCPRO?, (continued)
- Re: How and when to use GCPRO?, Daniel Colascione, 2010/12/27
- Re: How and when to use GCPRO?, Stefan Monnier, 2010/12/27
- Re: How and when to use GCPRO?, Daniel Colascione, 2010/12/27
- Re: How and when to use GCPRO?, Stefan Monnier, 2010/12/27
- Conservative scanning (was: Re: How and when to use GCPRO?), Daniel Colascione, 2010/12/27
- Re: How and when to use GCPRO?, Richard Stallman, 2010/12/28
- Re: How and when to use GCPRO?, Leo, 2010/12/27
- Common Lisp like feature expressions (was: How and when to use GCPRO?), Leo, 2010/12/27
- Re: Common Lisp like feature expressions (was: How and when to use GCPRO?), Andreas Schwab, 2010/12/27
- Re: Common Lisp like feature expressions (was: How and when to use GCPRO?), Leo, 2010/12/27
- Re: Common Lisp like feature expressions,
Stefan Monnier <=
- Re: Common Lisp like feature expressions, Leo, 2010/12/28