all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Ralph Schleicher <rs@ralph-schleicher.de>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 2951@emacsbugs.donarmstrong.com,
	Ralph Schleicher <rs@ralph-schleicher.de>
Subject: bug#2951: Suggestion: self-evaluating-p function
Date: Sat, 11 Apr 2009 23:35:04 +0200	[thread overview]
Message-ID: <87r5zy7u2f.fsf@echo.mueller-schleicher.i> (raw)
In-Reply-To: <jwvljq71her.fsf-monnier+emacsbugreports@gnu.org> (Stefan Monnier's message of "Sat\, 11 Apr 2009 08\:53\:45 -0400")

Stefan Monnier <monnier@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






  reply	other threads:[~2009-04-11 21:35 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-10 21:31 bug#2951: Suggestion: self-evaluating-p function Ralph Schleicher
2009-04-11 12:53 ` Stefan Monnier
2009-04-11 21:35   ` Ralph Schleicher [this message]
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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87r5zy7u2f.fsf@echo.mueller-schleicher.i \
    --to=rs@ralph-schleicher.de \
    --cc=2951@emacsbugs.donarmstrong.com \
    --cc=monnier@iro.umontreal.ca \
    /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.