unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* eval-when-compile vs defconst
@ 2006-11-11 14:39 Stephen Leake
  2006-11-11 17:01 ` Bob Rogers
  2006-11-12  5:14 ` Richard Stallman
  0 siblings, 2 replies; 11+ messages in thread
From: Stephen Leake @ 2006-11-11 14:39 UTC (permalink / raw)


I ran across this construct in ada-mode.el:

(eval-when-compile
  (defconst ada-95-string-keywords
    '("abstract" "aliased" "protected" "requeue" "tagged" "until")
    "List of keywords new in Ada 95.
Used to define `ada-*-keywords'."))

Is there any point to the 'eval-when-compile'? Help for
eval-when-compile says;

    Like `progn', but evaluates the body at compile time if you're
    compiling. Thus, the result of the body appears to the compiler as
    a quoted constant. In interpreted code, this is entirely
    equivalent to `progn'.

Since the body is already a quoted constant, this seems redundant. I
suspect the eval-when-compile is left over from a previous version
when functions where used to build the string.

But I'm not familiar with all of the nuances of byte-compiling, so I
thought I'd ask.

-- 
-- Stephe

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

* eval-when-compile vs defconst
  2006-11-11 14:39 eval-when-compile vs defconst Stephen Leake
@ 2006-11-11 17:01 ` Bob Rogers
  2006-11-11 17:03   ` Bob Rogers
  2006-11-12  5:14 ` Richard Stallman
  1 sibling, 1 reply; 11+ messages in thread
From: Bob Rogers @ 2006-11-11 17:01 UTC (permalink / raw)
  Cc: emacs-devel

   From: Stephen Leake <stephen_leake@member.fsf.org>
   Date: Sat, 11 Nov 2006 09:39:32 -0500

   I ran across this construct in ada-mode.el:

   (eval-when-compile
     (defconst ada-95-string-keywords
       '("abstract" "aliased" "protected" "requeue" "tagged" "until")
       "List of keywords new in Ada 95.
   Used to define `ada-*-keywords'."))

   Is there any point to the 'eval-when-compile'? Help for
   eval-when-compile says;

       Like `progn', but evaluates the body at compile time if you're
       compiling. Thus, the result of the body appears to the compiler as
       a quoted constant. In interpreted code, this is entirely
       equivalent to `progn'.

   Since the body is already a quoted constant, this seems redundant. I
   suspect the eval-when-compile is left over from a previous version
   when functions where used to build the string.

It says "the _result_ of the body", i.e. after compile-time evaluation.

					-- Bob Rogers
					   http://rgrjr.dyndns.org/

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

* eval-when-compile vs defconst
  2006-11-11 17:01 ` Bob Rogers
@ 2006-11-11 17:03   ` Bob Rogers
  0 siblings, 0 replies; 11+ messages in thread
From: Bob Rogers @ 2006-11-11 17:03 UTC (permalink / raw)


   From: Bob Rogers <rogers-emacs@rgrjr.dyndns.org>
   Date: Sat, 11 Nov 2006 12:01:14 -0500

      From: Stephen Leake <stephen_leake@member.fsf.org>
      Date: Sat, 11 Nov 2006 09:39:32 -0500

      I ran across this construct in ada-mode.el:

      (eval-when-compile
	(defconst ada-95-string-keywords
	  '("abstract" "aliased" "protected" "requeue" "tagged" "until")
	  "List of keywords new in Ada 95.
      Used to define `ada-*-keywords'."))

      . . .

   It says "the _result_ of the body", i.e. after compile-time evaluation.

Sorry; replied before thinking.  I think you're right; defconst
shouldn't need eval-when-compile.

					-- Bob

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

* Re: eval-when-compile vs defconst
  2006-11-11 14:39 eval-when-compile vs defconst Stephen Leake
  2006-11-11 17:01 ` Bob Rogers
@ 2006-11-12  5:14 ` Richard Stallman
  2006-11-12 14:29   ` Stephen Leake
  1 sibling, 1 reply; 11+ messages in thread
From: Richard Stallman @ 2006-11-12  5:14 UTC (permalink / raw)
  Cc: emacs-devel

    I ran across this construct in ada-mode.el:

    (eval-when-compile
      (defconst ada-95-string-keywords
	'("abstract" "aliased" "protected" "requeue" "tagged" "until")
	"List of keywords new in Ada 95.
    Used to define `ada-*-keywords'."))

    Is there any point to the 'eval-when-compile'? Help for
    eval-when-compile says;

No, you may as well define that variable in all cases.

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

* Re: eval-when-compile vs defconst
  2006-11-12  5:14 ` Richard Stallman
@ 2006-11-12 14:29   ` Stephen Leake
  2006-11-12 19:06     ` Markus Triska
  2006-11-13  9:43     ` Richard Stallman
  0 siblings, 2 replies; 11+ messages in thread
From: Stephen Leake @ 2006-11-12 14:29 UTC (permalink / raw)
  Cc: Stephen Leake, emacs-devel

Richard Stallman <rms@gnu.org> writes:

>     I ran across this construct in ada-mode.el:
>
>     (eval-when-compile
>       (defconst ada-95-string-keywords
> 	'("abstract" "aliased" "protected" "requeue" "tagged" "until")
> 	"List of keywords new in Ada 95.
>     Used to define `ada-*-keywords'."))
>
>     Is there any point to the 'eval-when-compile'? Help for
>     eval-when-compile says;
>
> No, you may as well define that variable in all cases.

Ok, thanks.

Now, how about this form:

(defvar ada-block-start-re
  (eval-when-compile
    (concat "\\<\\(" (regexp-opt '("begin" "declare" "else"
				   "exception" "generic" "loop" "or"
				   "private" "select" ))
	    "\\|\\(\\(limited\\|abstract\\|tagged\\)[ \t\n]+\\)*record\\)\\>"))
  "Regexp for keywords starting Ada blocks.")

Is the `eval-when-compile' useful here? I'm thinking it is.

The help for `defvar' says initvalue is evaluated, but it's not clear
whether that happens at compile time or load time.

-- 
-- Stephe

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

* Re: eval-when-compile vs defconst
  2006-11-12 14:29   ` Stephen Leake
@ 2006-11-12 19:06     ` Markus Triska
  2006-11-13  9:43     ` Richard Stallman
  1 sibling, 0 replies; 11+ messages in thread
From: Markus Triska @ 2006-11-12 19:06 UTC (permalink / raw)
  Cc: rms, emacs-devel

Stephen Leake <stephen_leake@member.fsf.org> writes:

> Is the `eval-when-compile' useful here? I'm thinking it is.
>
> The help for `defvar' says initvalue is evaluated, but it's not clear
> whether that happens at compile time or load time.

concat is recognized as a pure function by the optimizer and
evaluated. So no, eval-when-compile isn't useful in this case.

All the best! -- Markus Triska

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

* Re: eval-when-compile vs defconst
  2006-11-12 14:29   ` Stephen Leake
  2006-11-12 19:06     ` Markus Triska
@ 2006-11-13  9:43     ` Richard Stallman
  2006-11-13 18:41       ` Stuart D. Herring
  1 sibling, 1 reply; 11+ messages in thread
From: Richard Stallman @ 2006-11-13  9:43 UTC (permalink / raw)
  Cc: stephen_leake, emacs-devel


    (defvar ada-block-start-re
      (eval-when-compile
	(concat "\\<\\(" (regexp-opt '("begin" "declare" "else"
				       "exception" "generic" "loop" "or"
				       "private" "select" ))
		"\\|\\(\\(limited\\|abstract\\|tagged\\)[ \t\n]+\\)*record\\)\\>"))
      "Regexp for keywords starting Ada blocks.")

It would not be worth any extra complexity just to avoid one call to
concat when the file is loaded.  So even if eval-when-compile were not
a no-op here, I'd say take it out.

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

* Re: eval-when-compile vs defconst
  2006-11-13  9:43     ` Richard Stallman
@ 2006-11-13 18:41       ` Stuart D. Herring
  2006-11-13 18:46         ` Markus Triska
                           ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Stuart D. Herring @ 2006-11-13 18:41 UTC (permalink / raw)
  Cc: Stephen Leake, emacs-devel

>     (defvar ada-block-start-re
>       (eval-when-compile
> 	(concat "\\<\\(" (regexp-opt '("begin" "declare" "else"
> 				       "exception" "generic" "loop" "or"
> 				       "private" "select" ))
> 		"\\|\\(\\(limited\\|abstract\\|tagged\\)[ \t\n]+\\)*record\\)\\>"))
>       "Regexp for keywords starting Ada blocks.")
>
> It would not be worth any extra complexity just to avoid one call to
> concat when the file is loaded.  So even if eval-when-compile were not
> a no-op here, I'd say take it out.

Surely it's there to avoid calling (and loading) `regexp-opt' at load
time, and the concat is merely along for the ride?  Unless the optimizer
already evaluates calls to `regexp-opt' on quoted lists, it seems useful
to me.

Davis

-- 
This product is sold by volume, not by mass.  If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.

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

* Re: eval-when-compile vs defconst
  2006-11-13 18:41       ` Stuart D. Herring
@ 2006-11-13 18:46         ` Markus Triska
  2006-11-13 20:18         ` Stefan Monnier
  2006-11-14 12:27         ` Richard Stallman
  2 siblings, 0 replies; 11+ messages in thread
From: Markus Triska @ 2006-11-13 18:46 UTC (permalink / raw)
  Cc: Stephen Leake, Richard Stallman, emacs-devel

"Stuart D. Herring" <herring@lanl.gov> writes:

> Surely it's there to avoid calling (and loading) `regexp-opt' at load
> time, and the concat is merely along for the ride?  Unless the optimizer
> already evaluates calls to `regexp-opt' on quoted lists

It does that.

All the best! -- Markus Triska

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

* Re: eval-when-compile vs defconst
  2006-11-13 18:41       ` Stuart D. Herring
  2006-11-13 18:46         ` Markus Triska
@ 2006-11-13 20:18         ` Stefan Monnier
  2006-11-14 12:27         ` Richard Stallman
  2 siblings, 0 replies; 11+ messages in thread
From: Stefan Monnier @ 2006-11-13 20:18 UTC (permalink / raw)
  Cc: Stephen Leake, Richard Stallman, emacs-devel

> Surely it's there to avoid calling (and loading) `regexp-opt' at load
> time, and the concat is merely along for the ride?

Indeed.

> Unless the optimizer already evaluates calls to `regexp-opt' on quoted
> lists, it seems useful to me.

It used not to, but I believe it now should be properly optimized.


        Stefan

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

* Re: eval-when-compile vs defconst
  2006-11-13 18:41       ` Stuart D. Herring
  2006-11-13 18:46         ` Markus Triska
  2006-11-13 20:18         ` Stefan Monnier
@ 2006-11-14 12:27         ` Richard Stallman
  2 siblings, 0 replies; 11+ messages in thread
From: Richard Stallman @ 2006-11-14 12:27 UTC (permalink / raw)
  Cc: stephen_leake, emacs-devel

    Surely it's there to avoid calling (and loading) `regexp-opt' at load
    time, and the concat is merely along for the ride?  Unless the optimizer
    already evaluates calls to `regexp-opt' on quoted lists, it seems useful
    to me.

Indeed, to avoid loading regexp-opt might be worth the trouble.
(The time of running it isn't significant.)

So if it succeeds in doing that, it is worth keeping.

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

end of thread, other threads:[~2006-11-14 12:27 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-11-11 14:39 eval-when-compile vs defconst Stephen Leake
2006-11-11 17:01 ` Bob Rogers
2006-11-11 17:03   ` Bob Rogers
2006-11-12  5:14 ` Richard Stallman
2006-11-12 14:29   ` Stephen Leake
2006-11-12 19:06     ` Markus Triska
2006-11-13  9:43     ` Richard Stallman
2006-11-13 18:41       ` Stuart D. Herring
2006-11-13 18:46         ` Markus Triska
2006-11-13 20:18         ` Stefan Monnier
2006-11-14 12:27         ` Richard 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).