help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: `append' vs. `nconc'


From: tomas
Subject: Re: `append' vs. `nconc'
Date: Thu, 31 Dec 2015 10:22:53 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

-----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-----



reply via email to

[Prev in Thread] Current Thread [Next in Thread]