From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: John Mastro Newsgroups: gmane.emacs.help Subject: Re: beginnerquestion (nconc) Date: Tue, 21 Mar 2017 13:14:21 -0700 Message-ID: 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; charset=UTF-8 X-Trace: blaine.gmane.org 1490127329 24353 195.159.176.226 (21 Mar 2017 20:15:29 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 21 Mar 2017 20:15:29 +0000 (UTC) To: "help-gnu-emacs@gnu.org" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Mar 21 21:15:24 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 1cqQBa-0005JS-Un for geh-help-gnu-emacs@m.gmane.org; Tue, 21 Mar 2017 21:15:19 +0100 Original-Received: from localhost ([::1]:42237 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqQBg-00050j-Ka for geh-help-gnu-emacs@m.gmane.org; Tue, 21 Mar 2017 16:15:24 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53803) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cqQB2-0004zO-9b for help-gnu-emacs@gnu.org; Tue, 21 Mar 2017 16:14:45 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cqQB1-0008Gn-2O for help-gnu-emacs@gnu.org; Tue, 21 Mar 2017 16:14:44 -0400 Original-Received: from mail-qk0-x235.google.com ([2607:f8b0:400d:c09::235]:32957) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cqQB0-0008Gb-U8 for help-gnu-emacs@gnu.org; Tue, 21 Mar 2017 16:14:42 -0400 Original-Received: by mail-qk0-x235.google.com with SMTP id y76so144021407qkb.0 for ; Tue, 21 Mar 2017 13:14:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=vaHZ4kNtkqOFlyi/GwzT0mhS7pRcLaRILyz9KFV4Lm4=; b=aqxM/24txB50qIgDkj4uncUerZKlTqAiR5IaaT14VJWex3J996oVlTxig+AwIijMsH SFaZql9EjFzw4Z1iH1+P5ZGGwqmVS/LF8KmOyzGo05q2NzxJsYxc1/1KJ+Sye9bjU+bQ IVdKPkY1po8YGdgOFkHDTLutgd5Z38p5uHmT3XQMukkx9JS6rGSFsne/WRoM0sCN0fQY POcHztmqYXfx3roddhVbHouDWVU8JgNL/QiqrdEHJsfFgly8FF7+VPc+OGUhiuUYZJgR 8jFVrPr0QQruErwE/Ek0ZkEUOCD4WnU0TmzsJVdQfg18Cej0gyz1WjYfJEJshJQ89hO0 cqcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=vaHZ4kNtkqOFlyi/GwzT0mhS7pRcLaRILyz9KFV4Lm4=; b=gELc/iToGK9i9+x3hsquc1PHfZl98KvhOqQykgdikc8j7+1/tdkWCljz2etgMPuId2 PKPZuY82Qx9BQqyyYhK7qkActAJ00k9bOlCVXn9NA6LAk2kIflZS3o9xfQT0pQ7362VD fZAUSuLPhnjgXWohPK09axp1fTqd34B7z0KkUoSgifafadVpsKr8VbR6FM4h29vFaJit 9F5Fu5Jzl53/LjtOWxvBLwnkmzz2WZqlzI4KI6UIJMxy0WRzYHa55FxRIYIShuY1VeqY BojYyJZjwoomPmzqonWzWF+2boJOEkdQF+9oGQ0BPBt7CV5bImPaw0lt2UrwFb1PW6bu l1Lw== X-Gm-Message-State: AFeK/H1x7PLB5hgzbX9MMs+Rm18/Po3zIg3oh6bPlOOZG6g3+IA1KbmuxqSZozOGCv5asa8101Wlz5qJnqyjDg== X-Received: by 10.55.217.72 with SMTP id u69mr20834116qki.20.1490127281944; Tue, 21 Mar 2017 13:14:41 -0700 (PDT) Original-Received: by 10.237.49.162 with HTTP; Tue, 21 Mar 2017 13:14:21 -0700 (PDT) In-Reply-To: <87shm6d0r7.fsf@mail.de> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c09::235 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:112624 Archived-At: Stefan Huchler wrote: > Well to give you more context, most of the time I used doitems + > push. and push works the "right" way. so no reversing is needed: > > (dolist (item (append (let-alist kodi-properties .items) nil)) > (push (list (spiderbit-get-id item) > (vector `(,(spiderbit-get-name item) > id ,(spiderbit-get-show-id item)))) > tabulated-list-entries)) > > I could revert here kodi-properties I guess to get in the end what I > want? > > > > But now I needed a iterator in the alist assigend to the elements: > > (let* ((items (cdr (assoc 'items kodi-properties)))) > (dotimes (number (length items)) > (let* ((item (elt items number)) > (title (or (spiderbit-get-name item) > "None")) > (id number)) > (push (list `(,id) > (vector `(,title id ,id))) > tabulated-list-entries)))) > (setq tabulated-list-entries (nreverse tabulated-list-entries)) > > > So I would need to reverse here items and number or use something like > length - number as index? > > it just dont feels very natural. I dont know. It's not always a good candidate, but often you can use `mapcar' instead of `push' and `nreverse'. 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))))) 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 :) John