[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Appending lists
From: |
Emanuel Berg |
Subject: |
Re: Appending lists |
Date: |
Tue, 15 Jun 2021 02:46:54 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
Alexandr Vityazev wrote:
> (defvar newlist '())
> (append `(,city ,district) newlist)
Okay, but I think (list city district) looks better...
And no need for a default value if one sets it the line
after IMO.
Also, one would try not to mix abstract and applied names too
much, but I get it it was to demonstrate `append'. But since
newlist is nil I don't know how much of a demo it is,
actually. Hm...
(to the OP: an empty list is '() or (list) or nil, so when
something actually _is_ an empty list '() (and not just
something to indicate false, for instance) is a good way of
putting it since that's what an empty list looks like, almost.
this is neat as it works the other way around as well, i.e.
a non-empty list is interpreted as non-nil, so you can check
for a non-empty list e.g. like this (when lst ... ) useful
with recursion (e.g., tail-recursion, with the empty list as
the non-recursive/base case) but also here and there in
general, I'd say...)
Also check out `nconc'
(nconc '(1 2 3) '(4 5) '(6)) ; (1 2 3 4 5 6) - if this works for you, use it
(nconc '(1 2 3) '(4 5) 6 ) ; (1 2 3 4 5 . 6) - see, last "list" isn't a list!
There was a trick with nconc, you could reverse a list in
constant time, right? I think that was it but that's all
I remember.
--
underground experts united
https://dataswamp.org/~incal
- Appending lists, henri-biard, 2021/06/14
- Re: Appending lists, Pierpaolo Bernardi, 2021/06/14
- Re: Appending lists, Pierpaolo Bernardi, 2021/06/14
- Appending lists, henri-biard, 2021/06/14
- Re: Appending lists, Alexandr Vityazev, 2021/06/14
- Re: Appending lists,
Emanuel Berg <=
- Re: Appending lists, Emanuel Berg, 2021/06/15
- Re: Appending lists, tomas, 2021/06/15
- Re: Appending lists, Emanuel Berg, 2021/06/15
- Re: Appending lists, tomas, 2021/06/16
- Re: Appending lists, Jean Louis, 2021/06/16
- Re: Appending lists, tomas, 2021/06/16
- Re: Appending lists, Jean Louis, 2021/06/16
- Re: Appending lists, Emanuel Berg, 2021/06/16
- Using Emacs for business, Jean Louis, 2021/06/16
- Re: Using Emacs for business, Emanuel Berg, 2021/06/16