[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: `append' vs. `nconc'
From: |
Pascal J. Bourguignon |
Subject: |
Re: `append' vs. `nconc' |
Date: |
Thu, 31 Dec 2015 06:36:08 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
Emanuel Berg <embe8573@student.uu.se> writes:
> "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, same thing.
(nconc nil '(1 2 3)) has no side effect!
> The reason I thought it fitting was the definitions of
> `append' and `ncons'. Here I want to change
> `completion-ignored-extensions'. `append' doesn't
> change it, which is why the assignment with `setq' was
> there. If it can't be removed (well, in the form of
> `setf'), there is still the gain of not creating the
> list unnecessarily, which in this case is a matter of
> principle but in other cases (with long lists) is
> a performance bottleneck?
>
>> Always re-assign the modified list:
>>
>> (setf completion-ignored-extensions (nconc
>> completion-ignored-extensions (list ".bcf"
>> ".run.xml")))
>>
>> otherwise it will break when the place is bound to
>> nil. (nil is a symbol and cannot be mutated into
>> a cons cell!).
>
> ?
>
> What place is bound to nil, when?
Any place you want, when it is.
(let ((mylist '()))
(nconc mylist (list 1 2 3))
mylist)
--> nil
(setf completion-ignored-extensions '())
(nconc completion-ignored-extensions (list ".o"))
completion-ignored-extensions
--> nil
--
__Pascal Bourguignon__ http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk
- 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, 2015/12/31
- Message not available
- Re: `append' vs. `nconc',
Pascal J. Bourguignon <=
- Re: `append' vs. `nconc', Emanuel Berg, 2015/12/30
- Message not available
- Re: `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 available
- Re: `append' vs. `nconc', Barry Margolin, 2015/12/31
- Message not available
- Re: `append' vs. `nconc', Pascal J. Bourguignon, 2015/12/31