[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: Wed, 22 Mar 2017 01:32:26 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

John Mastro <> writes:

> It's not always a good candidate, but often you can use `mapcar' instead
> of `push' and `nreverse'.

yes I also thought about mapcar functions and lambda in the last few hours:

  (let* ((items (cdr (assoc 'items kodi-properties)))
         (ids (number-sequence 0 (- (length items) 1))))
    (setq tabulated-list-entries
           (lambda (id item)
             (let* ((title (or ;;(cdr (assoc 'title item))
                            (spiderbit-get-name item)
               (list `,id
                     (vector `(,title id ,id)))))        
           ids items) ))

I would even think about seq-position to get the id but that seems to be
not in 24.x version of seq.el

your solution looks interesting, too. first you also use at least 1
cl-... function I dont know what I have to thinb about that. isnt clisp
supposed to be ugly or bad? still everwhere you get suggestions about

often the non (cl-) prefixed stuff seem to be wrappers or renamed
commonlisp functions, too?

> As an example (with the warning that I'm not familiar with kodi,
> spiderbit, etc., so there may be problems with this):
> (setq tabulated-list-entries
>       (let ((id 0))
>         (mapcar (lambda (item)
>                   (let* ((title (or (spiderbit-get-name item) "None"))
>                          (entry (list `(,id) (vector `(,title id ,id)))))
>                     (setq id (1+ id)) ;; Or (cl-incf id)
>                     entry))
>                 (cdr (assoc 'items kodi-properties)))))

that you can access with lambda on stuff outside the lambda I did not
know and of course makes things much easier / clean.

(ohh well I just see that you did comment out the cl-incf call).

also you used one time let and one time let* only a mistake or has that
any meaning?

I thought let* is for most cases better?

Wow and you use let after setq I never thought about that, but of course
it should/will work.

I am much about learning by doing, and to learn on concrete use cases /
needs. seems to kind of work. Meanwhile people (most important me) can
use the badly programmed but good usable kodi-remote if they want :)

> The `push' plus `nreverse' idiom felt fairly unnatural to me too when I
> first encountered Lisp. Before that, my main programming experience was
> in Python, where the most natural way to work with lists (which are
> dynamic arrays in Python's case) is to append at the end. Now, a few
> years later, it feel natural enough, but perhaps that's Stockholm
> syndrome talking :)

yes I also used much python in the past. Well its more a emacs-lisp
specific thing right? I mean common-lisp has append. its not good for
performance critical stuff and huge amounts of data... which would be
pretty irrelevant for my usecase.

But ok, if it leads me to better coding style, so be it.

I did not use map and lambda very much in the past. But should start
doing that more :)

reply via email to

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