* Byte-compile constants in a function
@ 2012-07-03 16:57 Joe Riel
0 siblings, 0 replies; 5+ messages in thread
From: Joe Riel @ 2012-07-03 16:57 UTC (permalink / raw)
To: help-gnu-emacs
Is there a way to define constant/macros so that the value is expanded
during byte-compilation of a function that uses them?
For example, I want to do
(defconst tag-prompt ?>)
(defun check (char) (eq char tag-prompt))
where the byte-compilation of check is the same as that of
(defun check (char) (eq char ?>))
--
Joe Riel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Byte-compile constants in a function
[not found] <mailman.3953.1341335828.855.help-gnu-emacs@gnu.org>
@ 2012-07-03 20:26 ` José A. Romero L.
2012-07-04 6:07 ` Joe Riel
2012-07-04 13:26 ` Stefan Monnier
1 sibling, 1 reply; 5+ messages in thread
From: José A. Romero L. @ 2012-07-03 20:26 UTC (permalink / raw)
To: gnu.emacs.help; +Cc: help-gnu-emacs
W dniu wtorek, 3 lipca 2012 18:57:12 UTC+2 użytkownik Joe Riel napisał:
> Is there a way to define constant/macros so that the value is expanded
> during byte-compilation of a function that uses them?
(...)
How about defining an inlined function that returns the constant
you need?
(defsubst tag-prompt () ?>)
then:
(defun check (char) (eq char (tag-prompt)))
a quick look at the byte-compiled code shows that the value
of (tag-prompt) is indeed inlined.
Cheers,
--
José A. Romero L.
escherdragon at gmail
"We who cut mere stones must always be envisioning cathedrals."
(Quarry worker's creed)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Byte-compile constants in a function
2012-07-03 20:26 ` Byte-compile constants in a function José A. Romero L.
@ 2012-07-04 6:07 ` Joe Riel
0 siblings, 0 replies; 5+ messages in thread
From: Joe Riel @ 2012-07-04 6:07 UTC (permalink / raw)
To: help-gnu-emacs
On Tue, 3 Jul 2012 13:26:13 -0700 (PDT)
José A. Romero L. <escherdragon@gmail.com> wrote:
> W dniu wtorek, 3 lipca 2012 18:57:12 UTC+2 użytkownik Joe Riel napisał:
> > Is there a way to define constant/macros so that the value is expanded
> > during byte-compilation of a function that uses them?
> (...)
>
> How about defining an inlined function that returns the constant
> you need?
>
> (defsubst tag-prompt () ?>)
>
> then:
>
> (defun check (char) (eq char (tag-prompt)))
>
> a quick look at the byte-compiled code shows that the value
> of (tag-prompt) is indeed inlined.
Thanks, that does what I want.
--
Joe Riel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Byte-compile constants in a function
[not found] <mailman.3953.1341335828.855.help-gnu-emacs@gnu.org>
2012-07-03 20:26 ` Byte-compile constants in a function José A. Romero L.
@ 2012-07-04 13:26 ` Stefan Monnier
2012-07-05 2:42 ` Joe Riel
1 sibling, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2012-07-04 13:26 UTC (permalink / raw)
To: help-gnu-emacs
> (defconst tag-prompt ?>)
> (defun check (char) (eq char tag-prompt))
You can do
(eval-when-compile
(defconst tag-prompt ?>))
(defun check (char) (eq char (eval-when-compile tag-prompt)))
-- Stefan
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Byte-compile constants in a function
2012-07-04 13:26 ` Stefan Monnier
@ 2012-07-05 2:42 ` Joe Riel
0 siblings, 0 replies; 5+ messages in thread
From: Joe Riel @ 2012-07-05 2:42 UTC (permalink / raw)
To: help-gnu-emacs
On Wed, 04 Jul 2012 09:26:06 -0400
Stefan Monnier <monnier@iro.umontreal.ca> wrote:
> > (defconst tag-prompt ?>)
> > (defun check (char) (eq char tag-prompt))
>
> You can do
>
> (eval-when-compile
> (defconst tag-prompt ?>))
>
> (defun check (char) (eq char (eval-when-compile tag-prompt)))
>
>
> -- Stefan
Thanks, that seems nicer than using defsubst. Possibly with that
I'll finally understand what eval-when-compile is all about.
--
Joe Riel
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-07-05 2:42 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.3953.1341335828.855.help-gnu-emacs@gnu.org>
2012-07-03 20:26 ` Byte-compile constants in a function José A. Romero L.
2012-07-04 6:07 ` Joe Riel
2012-07-04 13:26 ` Stefan Monnier
2012-07-05 2:42 ` Joe Riel
2012-07-03 16:57 Joe Riel
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).