[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: if vs. when vs. and: style question
From: |
tomas |
Subject: |
Re: if vs. when vs. and: style question |
Date: |
Fri, 27 Mar 2015 10:20:51 +0100 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Fri, Mar 27, 2015 at 09:11:24AM +0100, Gian Uberto Lauri wrote:
> tomas@tuxteam.de writes:
[...]
> > That depends on the compiler. OTOH -- for a decent modern compiler, the
> > code generator would see the same, whether you type (+ 1 foo) or (1+ foo).
>
> Thank you very much.
To stay on topic (and to take the handwaving a bit out of the thread ;-), just
fire up a fairly recent Emacs, go to the *scratch* buffer (which should've come
up as default anyway), and type the following:
(defun incr (x) (1+ x))
With the cursor at the end of the expression, type "C-x e" (that is
eval-last-sexp).
You should see something in the echo area confirming that Emacs has grokked
that.
Just below, type this:
(disassemble 'incr)
closing off with "C-x e", as before. What do you see? Your function, expressed
as Emacs Lisp bytecodes (in a separate buffer). Something like:
byte code for incr:
args: (x)
0 varref x
1 add1
2 return
So hm. It seems: Elisp's byte code *has* a special instruction for "increment
by one", called, not surprisingly "add1".
Now repeat the experiment with the following, slightly modified lines:
(defun inc1 (x) (+ 1 x))
(disassemble 'inc1)
What's your result? What conclusions do you draw from that?
*My* point is: Emacs isn't just an editor (although it's very good at that).
It is an extremely discoverable programming environment. Just play with it.
It'll go out of its way to help you access its innards.
Regards
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
iEYEARECAAYFAlUVIPMACgkQBcgs9XrR2kY0JACfZnn7SMUzFtjnBFHIXtDPXypr
7BQAn1g+gpQfVC323+/3sLFNdMufnvH5
=gLJC
-----END PGP SIGNATURE-----
- Re: if vs. when vs. and: style question, (continued)
- Message not available
- Re: if vs. when vs. and: style question, Pascal J. Bourguignon, 2015/03/25
- Re: if vs. when vs. and: style question, Eli Zaretskii, 2015/03/25
- Message not available
- Re: if vs. when vs. and: style question, Rusi, 2015/03/25
- Re: if vs. when vs. and: style question, Rusi, 2015/03/25
- Re: if vs. when vs. and: style question, Emanuel Berg, 2015/03/31
- Re: if vs. when vs. and: style question, Rusi, 2015/03/31
- Message not available
- Re: if vs. when vs. and: style question, Emanuel Berg, 2015/03/26
- Re: if vs. when vs. and: style question, Gian Uberto Lauri, 2015/03/27
- Re: if vs. when vs. and: style question, tomas, 2015/03/27
- Re: if vs. when vs. and: style question, Gian Uberto Lauri, 2015/03/27
- Re: if vs. when vs. and: style question,
tomas <=
- Re: if vs. when vs. and: style question, Gian Uberto Lauri, 2015/03/27
- Message not available
- Re: if vs. when vs. and: style question, Pascal J. Bourguignon, 2015/03/27
- Re: if vs. when vs. and: style question, tomas, 2015/03/27
- Message not available
- Re: if vs. when vs. and: style question, Rusi, 2015/03/27
- Re: if vs. when vs. and: style question, Pascal J. Bourguignon, 2015/03/27
- Re: if vs. when vs. and: style question, Emanuel Berg, 2015/03/26
- Re: if vs. when vs. and: style question, Gian Uberto Lauri, 2015/03/27
- Message not available
- Re: if vs. when vs. and: style question, Joost Kremers, 2015/03/27
- Message not available
- Re: if vs. when vs. and: style question, Pascal J. Bourguignon, 2015/03/27
- Re: if vs. when vs. and: style question, Rusi, 2015/03/27