From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stefan Huchler Newsgroups: gmane.emacs.help Subject: Re: beginnerquestion (nconc) Date: Wed, 22 Mar 2017 01:32:26 +0100 Message-ID: <87mvcef8x1.fsf@jupiter.lan> References: <87shmc1m2u.fsf@mail.de> <87k27nzvo7.fsf@mail.de> <87shm6d0r7.fsf@mail.de> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1490142792 10824 195.159.176.226 (22 Mar 2017 00:33:12 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 22 Mar 2017 00:33:12 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Mar 22 01:33:02 2017 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cqUCy-0001ap-C4 for geh-help-gnu-emacs@m.gmane.org; Wed, 22 Mar 2017 01:33:00 +0100 Original-Received: from localhost ([::1]:48371 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqUD4-0002BG-7J for geh-help-gnu-emacs@m.gmane.org; Tue, 21 Mar 2017 20:33:06 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50054) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqUCd-0002Ay-MD for help-gnu-emacs@gnu.org; Tue, 21 Mar 2017 20:32:40 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cqUCa-00069b-K9 for help-gnu-emacs@gnu.org; Tue, 21 Mar 2017 20:32:39 -0400 Original-Received: from [195.159.176.226] (port=50863 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cqUCa-000685-Co for help-gnu-emacs@gnu.org; Tue, 21 Mar 2017 20:32:36 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1cqUCR-0006vG-RD for help-gnu-emacs@gnu.org; Wed, 22 Mar 2017 01:32:27 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 76 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:x+YxrnspyniL/B5TbSx+E49Q4+s= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:112625 Archived-At: 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 (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 :)