GNU bug report logs -
#2951
Suggestion: self-evaluating-p function
Previous Next
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 2951 in the body.
You can then email your comments to 2951 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>
:
bug#2951
; Package
emacs
.
(Fri, 10 Apr 2009 21:40:05 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Ralph Schleicher <rs <at> ralph-schleicher.de>
:
New bug report received and forwarded. Copy sent to
Emacs Bugs <bug-gnu-emacs <at> gnu.org>
.
(Fri, 10 Apr 2009 21:40:05 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> emacsbugs.donarmstrong.com (full text, mbox):
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 <at> ralph-schleicher.de>
+
+ * subr.el (self-evaluating-p): New function.
+
2008-09-05 Chong Yidong <cyd <at> 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 <at> ralph-schleicher.de>
+
+ * eval.texi (Self-Evaluating Forms): Add self-evaluating-p.
+
2008-09-05 Chong Yidong <cyd <at> 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
Severity set to `wishlist' from `normal'
Request was from
Glenn Morris <rgm <at> gnu.org>
to
control <at> emacsbugs.donarmstrong.com
.
(Sat, 11 Apr 2009 02:10:04 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>
:
bug#2951
; Package
emacs
.
(Sat, 11 Apr 2009 13:00:03 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Stefan Monnier <monnier <at> iro.umontreal.ca>
:
Extra info received and forwarded to list. Copy sent to
Emacs Bugs <bug-gnu-emacs <at> gnu.org>
.
(Sat, 11 Apr 2009 13:00:03 GMT)
Full text and
rfc822 format available.
Message #12 received at 2951 <at> emacsbugs.donarmstrong.com (full text, mbox):
> I would like to have a 'self-evaluating-p' function in Emacs to check
> whether or not a value has to be quoted.
I'm not necessarily opposed, but I'd first hear some arguments
explaining why/when one would need that.
Stefan
Information forwarded
to
bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>
:
bug#2951
; Package
emacs
.
(Sat, 11 Apr 2009 21:45:03 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Ralph Schleicher <rs <at> ralph-schleicher.de>
:
Extra info received and forwarded to list. Copy sent to
Emacs Bugs <bug-gnu-emacs <at> gnu.org>
.
(Sat, 11 Apr 2009 21:45:03 GMT)
Full text and
rfc822 format available.
Message #17 received at 2951 <at> emacsbugs.donarmstrong.com (full text, mbox):
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:
>> I would like to have a 'self-evaluating-p' function in Emacs to check
>> whether or not a value has to be quoted.
>
> I'm not necessarily opposed, but I'd first hear some arguments
> explaining why/when one would need that.
Okay, this is probably best explained by an example. I'm working on
an Emacs package for parsing numbers in a flexible way. That means
the regular expression string matching a number is a function of the
selected numeral system and set of numbers to match.
While some numeral systems have really different notations for numbers,
other systems are quite close to each other. This is especially true
for numeral systems of programming languages. Therefore it is natural
to define related numeral systems by inheritance:
(define-numeral-system Fortran
'((number-numerals "0123456789")
(number-zero "0")
(number-plus "+")
(number-minus "-")
(number-radix ".")
(number-exponent "DEde")
;; ...
)
"Numeral system for the Fortran programming language.")
(define-numeral-system C
(with-numeral-system 'Fortran
(setq number-exponent "Ee")
;; ...
(numeral-system-bindings t))
"Numeral system for the C programming language.")
The 'with-numeral-system' macro and 'numeral-system-bindings' function
are defined as follows.
(defmacro with-numeral-system (name &rest body)
"Evaluate BODY within numeral system NAME."
`(let ,(numeral-system-bindings (eval name))
,@body))
(defun numeral-system-bindings (name)
"Return the variable bindings for a numeral system.
Argument NAME is the symbolic name of a numeral system (a symbol).
A value of nil means to bind all symbols to nil, t means to bind
all symbols to their current value, and `default' means to bind all
symbols to their default values.
Return value is a `let'-like list of variable bindings."
(cond
;; ...
((eq name t)
(let (value)
(mapcar (lambda (symbol)
(setq value (symbol-value symbol))
;;;; ==>
(list symbol (if (self-evaluating-p value)
value
(list 'quote value))))
numeral-system-variables)))
;; ...
))
I noticed that if I don't check for a self-evaluating form here, the
variable bindings for a numeral system are improperly quoted in the
alist of numeral systems.
I hope these explanations are clear enough.
--
Ralph
Information forwarded
to
bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>
:
bug#2951
; Package
emacs
.
(Mon, 13 Apr 2009 17:55:04 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Stefan Monnier <monnier <at> iro.umontreal.ca>
:
Extra info received and forwarded to list. Copy sent to
Emacs Bugs <bug-gnu-emacs <at> gnu.org>
.
(Mon, 13 Apr 2009 17:55:04 GMT)
Full text and
rfc822 format available.
Message #22 received at 2951 <at> emacsbugs.donarmstrong.com (full text, mbox):
> (list symbol (if (self-evaluating-p value)
> value
> (list 'quote value))))
Why not just (list symbol (list 'quote value))) ?
Stefan
Information forwarded
to
bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>
:
bug#2951
; Package
emacs
.
(Mon, 13 Apr 2009 21:10:04 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Ralph Schleicher <rs <at> ralph-schleicher.de>
:
Extra info received and forwarded to list. Copy sent to
Emacs Bugs <bug-gnu-emacs <at> gnu.org>
.
(Mon, 13 Apr 2009 21:10:04 GMT)
Full text and
rfc822 format available.
Message #27 received at 2951 <at> emacsbugs.donarmstrong.com (full text, mbox):
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:
>> (list symbol (if (self-evaluating-p value)
>> value
>> (list 'quote value))))
>
> Why not just (list symbol (list 'quote value))) ?
Yes, this was my first attempt, too. But I got puzzled whether
or not the extra quote matters in any way, especiall with lambda
expressions. Since I couldn't find a satisfactory answer in the
Elisp reference manual, I decided to get rid of it just to be save.
So, If you tell me that the quote does no harm no matter what Lisp
object is quoted, I can live without a self-evaluating-p function.
--
Ralph
Information forwarded
to
bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>
:
bug#2951
; Package
emacs
.
(Tue, 14 Apr 2009 02:15:05 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Stefan Monnier <monnier <at> iro.umontreal.ca>
:
Extra info received and forwarded to list. Copy sent to
Emacs Bugs <bug-gnu-emacs <at> gnu.org>
.
(Tue, 14 Apr 2009 02:15:05 GMT)
Full text and
rfc822 format available.
Message #32 received at 2951 <at> emacsbugs.donarmstrong.com (full text, mbox):
>>> (list symbol (if (self-evaluating-p value)
>>> value
>>> (list 'quote value))))
>>
>> Why not just (list symbol (list 'quote value))) ?
> Yes, this was my first attempt, too. But I got puzzled whether
> or not the extra quote matters in any way, especiall with lambda
> expressions. Since I couldn't find a satisfactory answer in the
> Elisp reference manual, I decided to get rid of it just to be save.
> So, If you tell me that the quote does no harm no matter what Lisp
> object is quoted, I can live without a self-evaluating-p function.
By definition (self-evaluating-p VALUE) tests whether evaluating VALUE
or evaluating (quote VALUE) will return the same thing.
I.e. the quote does no harm.
Stefan
Information forwarded
to
bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>
:
bug#2951
; Package
emacs
.
(Tue, 14 Apr 2009 17:00:03 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Ralph Schleicher <rs <at> ralph-schleicher.de>
:
Extra info received and forwarded to list. Copy sent to
Emacs Bugs <bug-gnu-emacs <at> gnu.org>
.
(Tue, 14 Apr 2009 17:00:03 GMT)
Full text and
rfc822 format available.
Message #37 received at 2951 <at> emacsbugs.donarmstrong.com (full text, mbox):
Stefan Monnier <monnier <at> iro.umontreal.ca> writes:
>>>> (list symbol (if (self-evaluating-p value)
>>>> value
>>>> (list 'quote value))))
>>>
>>> Why not just (list symbol (list 'quote value))) ?
>
>> Yes, this was my first attempt, too. But I got puzzled whether
>> or not the extra quote matters in any way, especiall with lambda
>> expressions. Since I couldn't find a satisfactory answer in the
>> Elisp reference manual, I decided to get rid of it just to be save.
>
>> So, If you tell me that the quote does no harm no matter what Lisp
>> object is quoted, I can live without a self-evaluating-p function.
>
> By definition (self-evaluating-p VALUE) tests whether evaluating VALUE
> or evaluating (quote VALUE) will return the same thing.
> I.e. the quote does no harm.
Okay, thank you for your patience.
--
Ralph
bug closed, send any further explanations to Ralph Schleicher <rs <at> ralph-schleicher.de>
Request was from
Glenn Morris <rgm <at> gnu.org>
to
control <at> debbugs.gnu.org
.
(Wed, 20 Jan 2010 01:41:02 GMT)
Full text and
rfc822 format available.
bug archived.
Request was from
Debbugs Internal Request <bug-gnu-emacs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Wed, 17 Feb 2010 12:24:03 GMT)
Full text and
rfc822 format available.
This bug report was last modified 15 years and 126 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.