GNU bug report logs - #2951
Suggestion: self-evaluating-p function

Previous Next

Package: emacs;

Reported by: Ralph Schleicher <rs <at> ralph-schleicher.de>

Date: Fri, 10 Apr 2009 21:40:05 UTC

Severity: wishlist

Done: Glenn Morris <rgm <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Ralph Schleicher <rs <at> ralph-schleicher.de>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Ralph Schleicher <rs <at> ralph-schleicher.de>, 2951 <at> debbugs.gnu.org
Subject: bug#2951: Suggestion: self-evaluating-p function
Date: Sat, 11 Apr 2009 23:35:04 +0200
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




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.