From: Stefan Huchler <stefan.huchler@mail.de>
To: help-gnu-emacs@gnu.org
Subject: Re: beginnerquestion (nconc)
Date: Wed, 22 Mar 2017 01:32:26 +0100 [thread overview]
Message-ID: <87mvcef8x1.fsf@jupiter.lan> (raw)
In-Reply-To: CAOj2CQTYUESu0AG_WwoBKQfT80Psak4RNtN2W8DdX9K+9Qq0Vg@mail.gmail.com
John Mastro <john.b.mastro@gmail.com> 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
(mapcar*
(lambda (id item)
(let* ((title (or ;;(cdr (assoc 'title item))
(spiderbit-get-name item)
"None")))
(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
it.
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 :)
next prev parent reply other threads:[~2017-03-22 0:32 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-17 5:58 beginnerquestion (nconc) Stefan Huchler
2017-03-17 7:33 ` Thien-Thi Nguyen
2017-03-17 8:52 ` Thien-Thi Nguyen
2017-03-17 14:19 ` Stefan Huchler
2017-03-17 14:48 ` tomas
2017-03-17 14:42 ` Yuri Khan
2017-03-17 16:59 ` Stefan Huchler
2017-03-17 17:20 ` Drew Adams
2017-03-17 17:32 ` Drew Adams
2017-03-18 2:15 ` Stefan Monnier
2017-03-21 16:47 ` Stefan Huchler
2017-03-21 16:59 ` Stefan Huchler
2017-03-21 20:14 ` John Mastro
2017-03-22 0:32 ` Stefan Huchler [this message]
2017-03-22 15:02 ` Michael Heerdegen
2017-03-22 19:00 ` John Mastro
2017-03-21 11:05 ` Michael Heerdegen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87mvcef8x1.fsf@jupiter.lan \
--to=stefan.huchler@mail.de \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).