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

[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




reply via email to

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