[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: `append' vs. `nconc'
From: |
Emanuel Berg |
Subject: |
Re: `append' vs. `nconc' |
Date: |
Thu, 31 Dec 2015 19:48:01 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) |
<tomas@tuxteam.de> writes:
> 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.
However, because of the potential situation with
a symbol being nil or the empty list, `nconc' can't
really be used only "for effect" - so it should return
the list and that in turn be assigned!
So a little bit of functional programming still has to
be employed! (Not that the FP people has the monopoly
on returning stuff tho they might think so themselves
in their opium dreams.)
On the other hand, `append' isn't side-effect free!
(setq *digits* '(1 2 3 4 5))
(setq *chars* '(a b c d e))
(setq *appended-list* (append *digits* *chars*))
(setf (car (last *appended-list*)) 'x)
(insert (format " ; %s" *appended-list*)) ; (1 2 3 4 5 a b c d x)
(insert (format " ; %s" *chars*)) ; (a b c d x)
Perhaps (concatenate 'list ...) is the
functional function?
--
underground experts united
http://user.it.uu.se/~embe8573
- Re: Error: Setting the shell in sh-mode via a local variable does not work, (continued)
Re: Error: Setting the shell in sh-mode via a local variable does not work, Teemu Likonen, 2015/12/30
- `append' vs. `nconc' (was: Re: Error: Setting the shell in sh-mode via a local variable does not work), Emanuel Berg, 2015/12/30
- Re: `append' vs. `nconc', Teemu Likonen, 2015/12/30
- Re: `append' vs. `nconc', Emanuel Berg, 2015/12/30
- Message not available
- Re: `append' vs. `nconc', Pascal J. Bourguignon, 2015/12/30
- Re: `append' vs. `nconc', Emanuel Berg, 2015/12/30
- Re: `append' vs. `nconc', tomas, 2015/12/31
- Re: `append' vs. `nconc',
Emanuel Berg <=
Message not availableRe: `append' vs. `nconc', Pascal J. Bourguignon, 2015/12/31
Re: `append' vs. `nconc', Emanuel Berg, 2015/12/30
Message not availableRe: `append' vs. `nconc', Pascal J. Bourguignon, 2015/12/31
Re: `append' vs. `nconc', Emanuel Berg, 2015/12/31
Re: `append' vs. `nconc', tomas, 2015/12/31
side effects, list sharing [was: `append' vs. `nconc'], Drew Adams, 2015/12/31
Re: side effects, list sharing [was: `append' vs. `nconc'], Emanuel Berg, 2015/12/31
RE: side effects, list sharing [was: `append' vs. `nconc'], Drew Adams, 2015/12/31
Re: `append' vs. `nconc', Emanuel Berg, 2015/12/31
Message not availableRe: `append' vs. `nconc', Barry Margolin, 2015/12/31