unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* defvar'ing constants
@ 2005-06-24  3:54 Juanma Barranquero
  2005-06-25  0:31 ` Richard M. Stallman
  0 siblings, 1 reply; 12+ messages in thread
From: Juanma Barranquero @ 2005-06-24  3:54 UTC (permalink / raw)


*** Welcome to IELM ***  Type (describe-mode) for help.
ELISP> (defvar :k)
:k
ELISP> (defvar :k 1)
:k
ELISP> (defconst :k 1)
*** Eval error ***  Attempt to set a constant symbol: :k
ELISP> (set :k :k)
:k
ELISP> (set :k 1)
*** Eval error ***  Attempt to set a constant symbol: :k
ELISP> (set-default :k :k)
:k
ELISP> (set-default :k 1)
*** Eval error ***  Attempt to set a constant symbol: :k
ELISP> 

For consistency:

  (defvar CONSTANT)               ; should work
  (defvar CONSTANT ITS-VALUE)     ; should work
  (defvar CONSTANT OTHER-VALUE)   ; should fail

The attached patch implements this behavior.  I'm calling error
directly, copying the error message from set_internal; another idea
would be to allow the call to Fset_default to go through when

   NILP (tem) ||
   (SYMBOL_CONSTANT_P (sym) && !EQ (tem, tail))

which avoid duplicating the error checking and the message, but
doesn't seem clean to me.  Opinions?

-- 
                    /L/e/k/t/u


Index: src/eval.c
===================================================================
RCS file: /cvsroot/emacs/emacs/src/eval.c,v
retrieving revision 1.243
diff -u -2 -r1.243 eval.c
--- src/eval.c	23 Jun 2005 16:07:51 -0000	1.243
+++ src/eval.c	24 Jun 2005 03:42:47 -0000
@@ -793,4 +793,8 @@
       if (NILP (tem))
  	Fset_default (sym, Feval (Fcar (tail)));
+      else if (SYMBOL_CONSTANT_P (sym)
+               && !EQ (tem, tail))
+        error ("Attempt to set a constant symbol: %s",
+               SDATA (SYMBOL_NAME (sym)));
       else
 	{ /* Check if there is really a global binding rather than just a let

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: defvar'ing constants
  2005-06-24  3:54 defvar'ing constants Juanma Barranquero
@ 2005-06-25  0:31 ` Richard M. Stallman
  2005-06-25  4:14   ` Jay Belanger
                     ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Richard M. Stallman @ 2005-06-25  0:31 UTC (permalink / raw)
  Cc: emacs-devel

    For consistency:

      (defvar CONSTANT)               ; should work
      (defvar CONSTANT ITS-VALUE)     ; should work
      (defvar CONSTANT OTHER-VALUE)   ; should fail

I think it is more consistent to make them all errors.
defvar should not be used on these symbols.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: defvar'ing constants
  2005-06-25  0:31 ` Richard M. Stallman
@ 2005-06-25  4:14   ` Jay Belanger
  2005-06-25 13:05     ` Juanma Barranquero
  2005-06-25 21:31     ` David Kastrup
  2005-06-25 12:59   ` Juanma Barranquero
  2005-06-28  5:06   ` Stefan Monnier
  2 siblings, 2 replies; 12+ messages in thread
From: Jay Belanger @ 2005-06-25  4:14 UTC (permalink / raw)
  Cc: Juanma Barranquero, belanger, emacs-devel


"Richard M. Stallman" <rms@gnu.org> writes:

>     For consistency:
>
>       (defvar CONSTANT)               ; should work
>       (defvar CONSTANT ITS-VALUE)     ; should work
>       (defvar CONSTANT OTHER-VALUE)   ; should fail
>
> I think it is more consistent to make them all errors.
> defvar should not be used on these symbols.

If a constant is defined in one file but used in a second, is there
then a way of quieting the compiler when the second file is compiled?

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: defvar'ing constants
  2005-06-25  0:31 ` Richard M. Stallman
  2005-06-25  4:14   ` Jay Belanger
@ 2005-06-25 12:59   ` Juanma Barranquero
  2005-06-28  5:06   ` Stefan Monnier
  2 siblings, 0 replies; 12+ messages in thread
From: Juanma Barranquero @ 2005-06-25 12:59 UTC (permalink / raw)
  Cc: emacs-devel

> I think it is more consistent to make them all errors.
> defvar should not be used on these symbols.

OK, that's even easier. I'll implement it.

-- 
                    /L/e/k/t/u

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: defvar'ing constants
  2005-06-25  4:14   ` Jay Belanger
@ 2005-06-25 13:05     ` Juanma Barranquero
  2005-06-25 21:31     ` David Kastrup
  1 sibling, 0 replies; 12+ messages in thread
From: Juanma Barranquero @ 2005-06-25 13:05 UTC (permalink / raw)
  Cc: rms, emacs-devel

> If a constant is defined in one file but used in a second, is there
> then a way of quieting the compiler when the second file is compiled?

"Constants", in the sense used in this thread, are not defconsts
(which are really mutable), but keywords, and symbols defined in C
which are marked as constant (for example,
`enable-multibyte-characters').

-- 
                    /L/e/k/t/u

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: defvar'ing constants
  2005-06-25  4:14   ` Jay Belanger
  2005-06-25 13:05     ` Juanma Barranquero
@ 2005-06-25 21:31     ` David Kastrup
  2005-06-26  2:28       ` Jay Belanger
  1 sibling, 1 reply; 12+ messages in thread
From: David Kastrup @ 2005-06-25 21:31 UTC (permalink / raw)
  Cc: Juanma Barranquero, rms, emacs-devel

Jay Belanger <belanger@truman.edu> writes:

> "Richard M. Stallman" <rms@gnu.org> writes:
>
>>     For consistency:
>>
>>       (defvar CONSTANT)               ; should work
>>       (defvar CONSTANT ITS-VALUE)     ; should work
>>       (defvar CONSTANT OTHER-VALUE)   ; should fail
>>
>> I think it is more consistent to make them all errors.
>> defvar should not be used on these symbols.
>
> If a constant is defined in one file but used in a second, is there
> then a way of quieting the compiler when the second file is
> compiled?

(defconst CONSTANT)

would appear to be a nice form for doing that.  It is not valid right
now.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: defvar'ing constants
  2005-06-25 21:31     ` David Kastrup
@ 2005-06-26  2:28       ` Jay Belanger
  2005-08-01  1:39         ` Stephen J. Turnbull
  0 siblings, 1 reply; 12+ messages in thread
From: Jay Belanger @ 2005-06-26  2:28 UTC (permalink / raw)
  Cc: Juanma Barranquero, rms, belanger, emacs-devel


David Kastrup <dak@gnu.org> writes:
> Jay Belanger <belanger@truman.edu> writes:
...
>> If a constant is defined in one file but used in a second, is there
>> then a way of quieting the compiler when the second file is
>> compiled?
>
> (defconst CONSTANT)
>
> would appear to be a nice form for doing that.  It is not valid right
> now.

That would be nice.
A while back, there was a discussion along the lines of doing
something similar for functions,
(defun foo)
to keep the compiler happy.  I recall the idea (not mine) meeting
approval.  Perhaps it's still planned for a future release?

Jay

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: defvar'ing constants
  2005-06-25  0:31 ` Richard M. Stallman
  2005-06-25  4:14   ` Jay Belanger
  2005-06-25 12:59   ` Juanma Barranquero
@ 2005-06-28  5:06   ` Stefan Monnier
  2005-06-28  7:40     ` Juanma Barranquero
  2005-06-28 21:29     ` Richard M. Stallman
  2 siblings, 2 replies; 12+ messages in thread
From: Stefan Monnier @ 2005-06-28  5:06 UTC (permalink / raw)
  Cc: Juanma Barranquero, emacs-devel

>     For consistency:
>       (defvar CONSTANT)               ; should work
>       (defvar CONSTANT ITS-VALUE)     ; should work
>       (defvar CONSTANT OTHER-VALUE)   ; should fail

> I think it is more consistent to make them all errors.
> defvar should not be used on these symbols.

One case I know was consciously make to work is (defvar :foo :foo) so that
packages using :foo could be kept backward compatible with Emacs-19
where :foo is a normal variable because keywords don't exist.
Whether we should still cater to such thing is another question.


        Stefan

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: defvar'ing constants
  2005-06-28  5:06   ` Stefan Monnier
@ 2005-06-28  7:40     ` Juanma Barranquero
  2005-06-28 21:29     ` Richard M. Stallman
  1 sibling, 0 replies; 12+ messages in thread
From: Juanma Barranquero @ 2005-06-28  7:40 UTC (permalink / raw)
  Cc: rms, emacs-devel

On 6/28/05, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
> >     For consistency:
> >       (defvar CONSTANT)               ; should work
> >       (defvar CONSTANT ITS-VALUE)     ; should work
> >       (defvar CONSTANT OTHER-VALUE)   ; should fail

> One case I know was consciously make to work is (defvar :foo :foo) so that
> packages using :foo could be kept backward compatible with Emacs-19
> where :foo is a normal variable because keywords don't exist.

Aha, that's why set-default and friends go around a few hoops to allow
setting a keyword to itself. Thanks! Anyway, that was allowed in my
original patch (it's the second case shown above) but I removed it per
Richard's request. I can re-add it if deemed appropriate.

> Whether we should still cater to such thing is another question.

No idea whether it will be usual for people with Emacs 22.X to load
19.X packages :)

-- 
                    /L/e/k/t/u

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: defvar'ing constants
  2005-06-28  5:06   ` Stefan Monnier
  2005-06-28  7:40     ` Juanma Barranquero
@ 2005-06-28 21:29     ` Richard M. Stallman
  1 sibling, 0 replies; 12+ messages in thread
From: Richard M. Stallman @ 2005-06-28 21:29 UTC (permalink / raw)
  Cc: lekktu, emacs-devel

    One case I know was consciously make to work is (defvar :foo :foo) so that
    packages using :foo could be kept backward compatible with Emacs-19
    where :foo is a normal variable because keywords don't exist.
    Whether we should still cater to such thing is another question.

I had forgotten about that, because Emacs 19 was so long ago.

I think it is ok to forget about this, but _if_ the change bothers
people, we could change defvar to once again allow that case and that
case only.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: defvar'ing constants
  2005-06-26  2:28       ` Jay Belanger
@ 2005-08-01  1:39         ` Stephen J. Turnbull
  2005-08-01 16:46           ` Richard M. Stallman
  0 siblings, 1 reply; 12+ messages in thread
From: Stephen J. Turnbull @ 2005-08-01  1:39 UTC (permalink / raw)
  Cc: emacs-devel

Sorry this is old; getting back into emacs-devel after a long hiatus.

>>>>> "Jay" == Jay Belanger <belanger@truman.edu> writes:

    Jay> That would be nice.  A while back, there was a discussion
    Jay> along the lines of doing something similar for functions,
    Jay> (defun foo) to keep the compiler happy.  I recall the idea
    Jay> (not mine) meeting approval.  Perhaps it's still planned for
    Jay> a future release?

XEmacs has a whole suite of macros for checking whether things are
boundp or fboundp, and for locally declaring them to be f?boundp to
the compiler without using def* macros.  We have found them very
useful in suppressing spurious compiler warnings.  If there is
interest in using this code, they are not yet assigned to the FSF, but
at the present time they are 100% written by Ben Wing <ben@xemacs.org>
as far as I know.  You might ask Ben to assign the code and avoid
redundant work on this.

The only advantage I see over the (defvar foo) approach is that you
avoid spurious tags, but this can be convenient.

These macros do not require any changes to the byte-compiler (in
XEmacs, anyway), and can even be placed in a separate library and
require'd only in the files where they are used.  (I don't recommend
this, just demonstrating that they don't interfere with the normal byte
compiler.)

Cheers,

-- 
School of Systems and Information Engineering http://turnbull.sk.tsukuba.ac.jp
University of Tsukuba                    Tennodai 1-1-1 Tsukuba 305-8573 JAPAN
               Ask not how you can "do" free software business;
              ask what your business can "do for" free software.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: defvar'ing constants
  2005-08-01  1:39         ` Stephen J. Turnbull
@ 2005-08-01 16:46           ` Richard M. Stallman
  0 siblings, 0 replies; 12+ messages in thread
From: Richard M. Stallman @ 2005-08-01 16:46 UTC (permalink / raw)
  Cc: belanger, emacs-devel

      If there is
    interest in using this code, they are not yet assigned to the FSF, but
    at the present time they are 100% written by Ben Wing <ben@xemacs.org>
    as far as I know.  You might ask Ben to assign the code and avoid
    redundant work on this.

Experience says it isn't worth the effort to ask.  He would need
papers from Sun as well as signing them himself.

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2005-08-01 16:46 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-06-24  3:54 defvar'ing constants Juanma Barranquero
2005-06-25  0:31 ` Richard M. Stallman
2005-06-25  4:14   ` Jay Belanger
2005-06-25 13:05     ` Juanma Barranquero
2005-06-25 21:31     ` David Kastrup
2005-06-26  2:28       ` Jay Belanger
2005-08-01  1:39         ` Stephen J. Turnbull
2005-08-01 16:46           ` Richard M. Stallman
2005-06-25 12:59   ` Juanma Barranquero
2005-06-28  5:06   ` Stefan Monnier
2005-06-28  7:40     ` Juanma Barranquero
2005-06-28 21:29     ` Richard M. Stallman

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).