From: Ralph Schleicher <rs@ralph-schleicher.de>
To: bug-gnu-emacs@gnu.org
Subject: bug#2951: Suggestion: self-evaluating-p function
Date: Fri, 10 Apr 2009 23:31:07 +0200 [thread overview]
Message-ID: <87myaogpr8.fsf@echo.mueller-schleicher.i> (raw)
I would like to have a 'self-evaluating-p' function in Emacs to check
whether or not a value has to be quoted.
Please find attached a patch with an example implementation together
with ChangeLog entries and documentation.
diff -u emacs-22.3/lisp/ChangeLog.orig emacs-22.3/lisp/ChangeLogyes
--- emacs-22.3/lisp/ChangeLog.orig 2008-09-05 18:12:23.000000000 +0200
+++ emacs-22.3/lisp/ChangeLog 2009-04-10 22:52:48.000000000 +0200
@@ -1,3 +1,7 @@
+2009-04-10 Ralph Schleicher <rs@ralph-schleicher.de>
+
+ * subr.el (self-evaluating-p): New function.
+
2008-09-05 Chong Yidong <cyd@stupidchicken.com>
* Version 22.3 released.
diff -u emacs-22.3/lisp/subr.el.orig emacs-22.3/lisp/subr.el
--- emacs-22.3/lisp/subr.el.orig 2008-09-02 17:15:26.000000000 +0200
+++ emacs-22.3/lisp/subr.el 2009-04-10 22:51:26.000000000 +0200
@@ -185,6 +185,19 @@
(while t
(signal 'error (list (apply 'format args)))))
+(defun self-evaluating-p (object)
+ "Return t if OBJECT is a self-evaluating form.
+That means OBJECT is neither a symbol nor a list except for
+nil (which is a symbol and a list), t (which is a symbol),
+keywords (which are symbols), and lambda expressions (which
+are lists)."
+ (if (symbolp object)
+ (or (eq object nil)
+ (eq object t)
+ (keywordp object))
+ (or (atom object)
+ (eq (car object) 'lambda))))
+
;; We put this here instead of in frame.el so that it's defined even on
;; systems where frame.el isn't loaded.
(defun frame-configuration-p (object)
diff -u emacs-22.3/lispref/ChangeLog.orig emacs-22.3/lispref/ChangeLog
--- emacs-22.3/lispref/ChangeLog.orig 2008-09-05 18:12:32.000000000 +0200
+++ emacs-22.3/lispref/ChangeLog 2009-04-10 22:52:32.000000000 +0200
@@ -1,3 +1,7 @@
+2009-04-10 Ralph Schleicher <rs@ralph-schleicher.de>
+
+ * eval.texi (Self-Evaluating Forms): Add self-evaluating-p.
+
2008-09-05 Chong Yidong <cyd@stupidchicken.com>
* Version 22.3 released.
diff -u emacs-22.3/lispref/eval.texi.orig emacs-22.3/lispref/eval.texi
--- emacs-22.3/lispref/eval.texi.orig 2008-01-07 09:49:06.000000000 +0100
+++ emacs-22.3/lispref/eval.texi 2009-04-10 22:43:34.000000000 +0200
@@ -178,6 +178,36 @@
@end group
@end example
+@defun self-evaluating-p object
+This function returns @code{t} if @var{object} is a self-evaluating
+form. That means, @var{object} is neither a symbol nor a list except
+for @code{nil} (which is a symbol and a list), @code{t} (which is a
+symbol), keywords (which are symbols), and lambda expressions (which
+are lists). @xref{Constant Variables}, and @ref{Lambda Expressions},
+for more information.
+@end defun
+
+ Please note that @code{self-evaluating-p} only flags those symbols
+as self-evaluating forms where the result does not depend on scope.
+
+@example
+@group
+(setq foo 1)
+ @result{} 1
+(self-evaluating-p 'foo)
+ @result{} nil
+(let ((foo 'foo))
+ (self-evaluating-p 'foo))
+ @result{} nil
+;; @r{Likewise with @code{eq}.}
+(eq 'foo foo)
+ @result{} nil
+(let ((foo 'foo))
+ (eq 'foo foo))
+ @result{} t
+@end group
+@end example
+
@node Symbol Forms
@subsection Symbol Forms
@cindex symbol evaluation
--
Ralph
next reply other threads:[~2009-04-10 21:31 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-10 21:31 Ralph Schleicher [this message]
2009-04-11 12:53 ` bug#2951: Suggestion: self-evaluating-p function Stefan Monnier
2009-04-11 21:35 ` Ralph Schleicher
2009-04-13 17:49 ` Stefan Monnier
2009-04-13 21:04 ` Ralph Schleicher
2009-04-14 2:06 ` Stefan Monnier
2009-04-14 16:53 ` Ralph Schleicher
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87myaogpr8.fsf@echo.mueller-schleicher.i \
--to=rs@ralph-schleicher.de \
--cc=2951@emacsbugs.donarmstrong.com \
--cc=bug-gnu-emacs@gnu.org \
/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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).