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

[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




reply via email to

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