From: <tomas@tuxteam.de>
To: help-gnu-emacs@gnu.org
Subject: Re: `append' vs. `nconc'
Date: Thu, 31 Dec 2015 10:22:53 +0100 [thread overview]
Message-ID: <20151231092253.GA19900@tuxteam.de> (raw)
In-Reply-To: <87wprvqnco.fsf@debian.uxu>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Thu, Dec 31, 2015 at 05:00:07AM +0100, Emanuel Berg wrote:
> "Pascal J. Bourguignon" <pjb@informatimago.com>
> writes:
>
> >> OK, so for example this: (setq
> >> completion-ignored-extensions (append
> >> completion-ignored-extensions '(".bcf" ".run.xml"))
> >> ) Is better as: (nconc completion-ignored-extensions
> >> (list ".bcf" ".run.xml")) ?
> >
> > No. You should never use nconc only for effect (just
> > like delete, etc).
>
> What do you mean by "effect"?
Side effect, the big lurking Monster for functional programmers:
(defvar foo 15)
(defun monster ()
(setq foo 42))
(monster)
;; now foo is 42: Gaaah!
(message "%S" foo)
Nconc has a side effect: after calling it, many of the lists are
changed.
Side effects make things more "interesting", because now things depend
on the order of evaluation of things: it does matter, e.g. wheter you
evaluate the arguments of a function (call) left-to-right or right-to-left
(or random!). Things like that. The equivalent in C might be
int i = 42;
printf("%d %d %d\n", i++, i++, i++)
or the classic:
a[i] = i++;
(which leads to undefined behaviour, because compiler writers need some
wiggling room to make efficient compilers!).
Sometimes you call functions because you *want* the side effect (aka
"calling for effect"), as in
(message "Happy New Year!")
So-called "pure functional languages" have to go towards some "interesting"
contortions for that.
Regards
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
iEYEARECAAYFAlaE8+0ACgkQBcgs9XrR2kYE0QCfcFXQTDijDWoh4GQKerTVEuuw
ragAn2SMKqwM3yfp5LQQt5MLQAEgdMjV
=iPp+
-----END PGP SIGNATURE-----
next prev parent reply other threads:[~2015-12-31 9:22 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-12-28 16:35 Error: Setting the shell in sh-mode via a local variable does not work Johannes Kastl
2015-12-29 1:32 ` Emanuel Berg
2015-12-29 18:33 ` Johannes Kastl
2015-12-30 14:53 ` Emanuel Berg
2015-12-30 15:15 ` Robert Thorpe
2015-12-30 15:30 ` Emanuel Berg
2015-12-30 17:42 ` Johannes Kastl
2015-12-30 15:19 ` Teemu Likonen
2015-12-30 15:41 ` `append' vs. `nconc' (was: Re: Error: Setting the shell in sh-mode via a local variable does not work) Emanuel Berg
2015-12-30 16:37 ` `append' vs. `nconc' Teemu Likonen
2015-12-31 3:37 ` Emanuel Berg
[not found] ` <mailman.1400.1451533083.843.help-gnu-emacs@gnu.org>
2015-12-31 3:45 ` Pascal J. Bourguignon
2015-12-31 4:00 ` Emanuel Berg
2015-12-31 9:22 ` tomas [this message]
2015-12-31 18:48 ` Emanuel Berg
[not found] ` <mailman.1402.1451534421.843.help-gnu-emacs@gnu.org>
2015-12-31 5:36 ` Pascal J. Bourguignon
2015-12-31 3:50 ` Emanuel Berg
[not found] ` <mailman.1401.1451533833.843.help-gnu-emacs@gnu.org>
2015-12-31 5:37 ` Pascal J. Bourguignon
2015-12-31 7:13 ` Emanuel Berg
2015-12-31 9:30 ` tomas
2015-12-31 17:56 ` side effects, list sharing [was: `append' vs. `nconc'] Drew Adams
2015-12-31 19:00 ` Emanuel Berg
2015-12-31 19:15 ` Drew Adams
2016-01-01 13:20 ` Emanuel Berg
2015-12-31 18:51 ` `append' vs. `nconc' Emanuel Berg
[not found] ` <mailman.1440.1451588113.843.help-gnu-emacs@gnu.org>
2016-01-01 2:53 ` Barry Margolin
2016-01-01 13:26 ` Emanuel Berg
[not found] ` <mailman.1406.1451546036.843.help-gnu-emacs@gnu.org>
2015-12-31 8:54 ` Pascal J. Bourguignon
2015-12-31 7:31 ` Teemu Likonen
2015-12-31 18:35 ` Emanuel Berg
2015-12-31 20:04 ` Teemu Likonen
2016-01-01 13:23 ` Emanuel Berg
2016-01-01 14:02 ` Teemu Likonen
2016-01-01 18:31 ` Emanuel Berg
[not found] ` <mailman.1438.1451586967.843.help-gnu-emacs@gnu.org>
2016-01-01 6:25 ` Pascal J. Bourguignon
2016-01-01 13:31 ` Emanuel Berg
2016-01-01 15:04 ` Drew Adams
[not found] ` <mailman.1353.1451490125.843.help-gnu-emacs@gnu.org>
2015-12-30 16:18 ` Pascal J. Bourguignon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20151231092253.GA19900@tuxteam.de \
--to=tomas@tuxteam.de \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.