[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: beginnerquestion (nconc)

From: Stefan Huchler
Subject: Re: beginnerquestion (nconc)
Date: Fri, 17 Mar 2017 15:19:28 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (gnu/linux)

Thien-Thi Nguyen <> writes:

> Was that documentation by any chance "(elisp) Rearrangement"?
> That info node describes "A common pitfall...".

possible, but the pitfall more looks like 2 symbols are the the equal
object, I dont see how that refers to that problem.

> Personally, these days i prefer ‘cl-loop’ for non-trivial stuff:
>  (cl-loop
>   for n below 5
>   collect (intern (string (+ ?a n))))
>  => (a b c d e)

I thought the reason why rms dont likes/supports commonlisp is because
its so ugly api? If push + nconc (and no other elisp alternative does
the right thing, and you get forced to use a setq + nreverse at the end)
I have a very different idea about what ugly is apperently.

> If you MUST use ‘nconc’, a common trick is to init the var w/ a
> throwaway head, to be ignored (afterwards) via ‘(cdr var)’.
>  (setq test3 (list 'MGMT))  ; overhead?  underfoot?  both?  :-D
>  (nconc test3 (list '(a)))
>  (nconc test3 (list '(b)))
>  (cdr test3)

because I need that a..b in that specific varible tabulated-list-entries

that means I need to do a:

(setq tabulated-list-entries (cdr tabulated-list-entries))

which is horrible code.

I guess using a shorter 2nd symbol before the setq makes the source look
slightly less horrible.

So to make it short I have to live with this horrible state or use some
custom own wrapper, I am shure I am the first who tries such stuff in
elisp, cracy me. (sorry need my green tea to get out of troll mode :) )

I just wonder with that limitation I dont see any usecase for nconc, how
are you supposed to initialise with setq the first value in a loop, that
makes zero sense.

Well lets try it differently, maybe my way of iterating through stuff is
bad thats the code I want to be cleaner:

  (setq tabulated-list-entries '())
  (let* ((items (cdr (assoc 'items kodi-properties))))
    (dotimes (number (length items))
      (let* ((item (elt items number))
             (title (or ;; (cdr (assoc 'title item))
             (id number))
        (push (list `(,id)
                    (vector `(,title id ,id)))
  (setq tabulated-list-entries (nreverse tabulated-list-entries))

maybe some lambda magic? I rewrote it from a dolist version because I
need the iterator for the id.

if nreverse would directly change tabulated-list-entries I could live
with that, even that would still be ugly, but really such clunky ugly
setq statement to get what you expect in the first place?

I guess cdr with fake entry seems to be the least horrible solution of
the suggestions I guess


Thank You!

reply via email to

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