* Re: emacs evaluating
[not found] ` <gmjvvq$fuv$1@gregory.bnet.hr>
@ 2009-02-07 14:18 ` Pascal J. Bourguignon
2009-02-07 14:36 ` Xah Lee
2009-02-07 20:55 ` Evans Winner
0 siblings, 2 replies; 6+ messages in thread
From: Pascal J. Bourguignon @ 2009-02-07 14:18 UTC (permalink / raw)
To: help-gnu-emacs
"Haris Bogdanoviæ" <fbogdanovic@xnet.hr> writes:
> "Haris Bogdanoviæ" <fbogdanovic@xnet.hr> wrote in message
> news:gmir6e$cno$1@gregory.bnet.hr...
>> Hi.
>>
>> When I write a function in emacs, how can I try it ?
Emacs questions are better asked on news:gnu.emacs.help
Type C-x C-e with the point after the function source to enter it into
the emacs lisp image.
They type (your-function your-argument) C-x C-e to evaluate it.
If you type C-y C-x C-e instead, the result of the expression will be
inserted in the buffer at the point.
(+ 1 2) C-u C-x C-e --> 3
(defun f (x) (if (< x 1) 1 (* x (f (1- x))))) C-x C-e
(f 9) C-u C-x C-e --> 362880
You don't need to compile your emacs lisp functions to use them. At
least not until they're debugged.
>> Can I open some window (buffer) for evaluating ?
Yes. M-x ielm RET gives you an interactive REPL to emacs lisp.
> When I try to compile function it gives me "make -k" command, I press enter
> and I get error message.
> Does emacs have lisp interpreter or I have to install it separatelly ?
You can get information about what an emacs command purpose is with:
C-h f compile RET
As you can see, compile has nothing to do with compiling emacs lisp
code.
It could be used to compile an emacs lisp source, if you defined a
Makefile or used the emacs command to do so. For example, you could
use:
emacs --eval '(byte-compile-file "source.el")'
to compile source.el into source.elc with emacs.
But we prefer to do it more interactively in lisp:
To compile a function: (byte-compile 'your-function) C-x C-e
To compile an emacs lisp source file: M-x byte-compile-file RET source.el RET
To load an emacs lisp source: M-x load-file RET source.el RET
To evaluate a while buffer: M-x eval-buffer RET
--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
----------> http://www.netmeister.org/news/learn2quote.html <-----------
---> http://homepage.ntlworld.com/g.mccaughan/g/remarks/uquote.html <---
__Pascal Bourguignon__ http://www.informatimago.com/
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: emacs evaluating
2009-02-07 14:18 ` emacs evaluating Pascal J. Bourguignon
@ 2009-02-07 14:36 ` Xah Lee
2009-02-07 20:55 ` Evans Winner
1 sibling, 0 replies; 6+ messages in thread
From: Xah Lee @ 2009-02-07 14:36 UTC (permalink / raw)
To: help-gnu-emacs
On Feb 7, 6:18 am, p...@informatimago.com (Pascal J. Bourguignon)
wrote:
> "Haris Bogdanoviæ" <fbogdano...@xnet.hr> writes:
> > "Haris Bogdanoviæ" <fbogdano...@xnet.hr> wrote in message
> >news:gmir6e$cno$1@gregory.bnet.hr...
> >> Hi.
>
> >> When I write a function in emacs, how can I try it ?
>
> Emacs questions are better asked on news:gnu.emacs.help
Please feel free to post emacs lisp question in comp.lang.lisp.
There are some Common Lisp fanatics, who often sneer emacs lisp (and
any other lisps) and they often try to drive any non Common Lisp
questions outside of comp.lang.lisp.
Xah
∑ http://xahlee.org/
☄
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: emacs evaluating
2009-02-07 14:18 ` emacs evaluating Pascal J. Bourguignon
2009-02-07 14:36 ` Xah Lee
@ 2009-02-07 20:55 ` Evans Winner
2009-02-07 21:25 ` Xah Lee
` (2 more replies)
1 sibling, 3 replies; 6+ messages in thread
From: Evans Winner @ 2009-02-07 20:55 UTC (permalink / raw)
To: help-gnu-emacs
pjb@informatimago.com (Pascal J. Bourguignon) writes:
To compile a function: (byte-compile 'your-function) C-x
C-e
I had never thought of this. I think I really must not
understand compilation very clearly. I think I grasp that
an entire file full of functions will load faster if it is
compiled first, but what does interactively compiling a
single function buy me? Does it exist in a different form
in the image when you do that? Does it execute faster?
(This is not a facetious question, by the way.) Er, maybe
it has to do with debugging macros or something...?
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: emacs evaluating
2009-02-07 20:55 ` Evans Winner
@ 2009-02-07 21:25 ` Xah Lee
2009-02-07 22:23 ` Pascal J. Bourguignon
2009-02-07 22:33 ` Michael Ekstrand
2 siblings, 0 replies; 6+ messages in thread
From: Xah Lee @ 2009-02-07 21:25 UTC (permalink / raw)
To: help-gnu-emacs
On Feb 7, 12:55 pm, Evans Winner <tho...@timbral.net> wrote:
> p...@informatimago.com (Pascal J. Bourguignon) writes:
>
> To compile a function: (byte-compile 'your-function) C-x
> C-e
>
> I had never thought of this. I think I really must not
> understand compilation very clearly. I think I grasp that
> an entire file full of functions will load faster if it is
> compiled first, but what does interactively compiling a
> single function buy me? Does it exist in a different form
> in the image when you do that? Does it execute faster?
> (This is not a facetious question, by the way.) Er, maybe
> it has to do with debugging macros or something...?
it'll speed up loading, and also execution.
• Speed of Byte-Code - GNU Emacs Lisp Reference Manual
http://xahlee.org/elisp/Speed-of-Byte_002dCode.html
you can try to test the code in that page (which contain comparison
that ran in 1994!)
there are some packages that's over 10k lines. e.g. js2, nxml,
ejacs... you can also try the speed comparison using these ...
Xah
∑ http://xahlee.org/
☄
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: emacs evaluating
2009-02-07 20:55 ` Evans Winner
2009-02-07 21:25 ` Xah Lee
@ 2009-02-07 22:23 ` Pascal J. Bourguignon
2009-02-07 22:33 ` Michael Ekstrand
2 siblings, 0 replies; 6+ messages in thread
From: Pascal J. Bourguignon @ 2009-02-07 22:23 UTC (permalink / raw)
To: help-gnu-emacs
Evans Winner <thorne@timbral.net> writes:
> pjb@informatimago.com (Pascal J. Bourguignon) writes:
>
> To compile a function: (byte-compile 'your-function) C-x
> C-e
>
> I had never thought of this. I think I really must not
> understand compilation very clearly. I think I grasp that
> an entire file full of functions will load faster if it is
> compiled first, but what does interactively compiling a
> single function buy me?
Depends.
> Does it exist in a different form
> in the image when you do that?
Yes.
Evaluate the following forms:
(defun fact (x)
(if (< x 1)
(/ x 0)
(* x (fact (1- x)))))
(symbol-function 'fact)
(byte-compile 'fact)
(symbol-function 'fact)
> Does it execute faster?
Possibly. Well the purpose is definitely to make it faster, and in
most cases, it might succeed.
However, if you must take into account the time taken by byte-compile
itself, it might not be faster globally. In some cases, it may be
better not to compile.
> (This is not a facetious question, by the way.) Er, maybe
> it has to do with debugging macros or something...?
It has an impact on the debugging yes. Compiled functions leave less
information to the debugger, so it may be harder to debug them.
Evaluate the following forms in turn.
(defun fact (x)
(if (< x 1)
(/ x 0)
(* x (fact (1- x)))))
(setq debug-on-error t)
(fact 5)
(byte-compile 'fact)
(fact 5)
(you can type q to exit from the debugger ; this is not a form)
Then try to evaluate the following forms in turn:
(defun get-internal-real-time ()
(destructuring-bind (hi lo msec) (current-time)
(+ (/ msec 1000000.0) lo (* hi 65536.0))))
(defmacro time (&rest body)
"Common-Lisp: time evaluates form in the current environment (lexical and \
dynamic). A call to time can be compiled.
DO: time prints various timing data and other information to trace output.
The nature and format of the printed information is
implementation-defined . Implementations are encouraged to provide
such information as elapsed real time, machine run time, and storage
management statistics.
"
(let ((start (gensym))
(result (gensym))
(stop (gensym))
(time (gensym)))
`(let* ((,start (get-internal-real-time))
(,result (progn ,@body))
(,stop (get-internal-real-time))
(,time (- ,stop ,start)) )
(insert (format "Time: %e ms\n" (* 1000 ,time))))))
(defun fact (x)
(if (< x 1)
1
(* x (fact (1- x)))))
(time (fact 2000))
(byte-compile 'fact)
(time (fact 2000))
--
__Pascal Bourguignon__
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: emacs evaluating
2009-02-07 20:55 ` Evans Winner
2009-02-07 21:25 ` Xah Lee
2009-02-07 22:23 ` Pascal J. Bourguignon
@ 2009-02-07 22:33 ` Michael Ekstrand
2 siblings, 0 replies; 6+ messages in thread
From: Michael Ekstrand @ 2009-02-07 22:33 UTC (permalink / raw)
To: help-gnu-emacs
Evans Winner <thorne@timbral.net> writes:
> pjb@informatimago.com (Pascal J. Bourguignon) writes:
>
> To compile a function: (byte-compile 'your-function) C-x
> C-e
>
> I had never thought of this. I think I really must not
> understand compilation very clearly. I think I grasp that
> an entire file full of functions will load faster if it is
> compiled first, but what does interactively compiling a
> single function buy me? Does it exist in a different form
> in the image when you do that? Does it execute faster?
> (This is not a facetious question, by the way.) Er, maybe
> it has to do with debugging macros or something...?
It doesn't buy you anything useful that I know of for interactive
experimentation. Byte compilation is useful for speeding up loading of
large and relatively-immutable packages, but for experimenting using C-x
C-e (evaluate last expression) and the scratch buffer are rather
convenient. Compiling also makes debugging more difficult, as the
debugger doesn't display overly useful information when it encounters
byte-compiled code.
- Michael
--
mouse, n: A device for pointing at the xterm in which you want to type.
Confused by the strange files? I cryptographically sign my messages.
For more information see <http://www.elehack.net/resources/gpg>.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2009-02-07 22:33 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <gmir6e$cno$1@gregory.bnet.hr>
[not found] ` <gmjvvq$fuv$1@gregory.bnet.hr>
2009-02-07 14:18 ` emacs evaluating Pascal J. Bourguignon
2009-02-07 14:36 ` Xah Lee
2009-02-07 20:55 ` Evans Winner
2009-02-07 21:25 ` Xah Lee
2009-02-07 22:23 ` Pascal J. Bourguignon
2009-02-07 22:33 ` Michael Ekstrand
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).