From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Leo <sdl.web@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: Common Lisp like feature expressions
Date: Mon, 27 Dec 2010 20:01:02 -0500 [thread overview]
Message-ID: <jwvpqsmn2be.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <m18vzbgf98.fsf@cam.ac.uk> (Leo's message of "Mon, 27 Dec 2010 19:57:55 +0000")
> (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
next prev parent reply other threads:[~2010-12-28 1:01 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-27 9:21 How and when to use GCPRO? Leo
2010-12-27 10:15 ` Andreas Schwab
2010-12-27 10:38 ` Leo
2010-12-27 11:17 ` Andreas Schwab
2010-12-27 16:00 ` Stefan Monnier
2010-12-27 17:51 ` Andreas Schwab
2010-12-28 1:01 ` Stefan Monnier
2010-12-28 1:33 ` Daniel Colascione
2010-12-28 2:17 ` Stefan Monnier
2010-12-28 3:37 ` Daniel Colascione
2010-12-28 4:15 ` Stefan Monnier
2010-12-28 4:36 ` Conservative scanning (was: Re: How and when to use GCPRO?) Daniel Colascione
2010-12-28 17:07 ` How and when to use GCPRO? Richard Stallman
2010-12-27 19:15 ` Leo
2010-12-27 19:26 ` Common Lisp like feature expressions (was: How and when to use GCPRO?) Leo
2010-12-27 19:38 ` Andreas Schwab
2010-12-27 19:57 ` Leo
2010-12-28 1:01 ` Stefan Monnier [this message]
2010-12-28 15:26 ` Common Lisp like feature expressions Leo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvpqsmn2be.fsf-monnier+emacs@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=emacs-devel@gnu.org \
--cc=sdl.web@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.