From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Jean-Christophe Helary Newsgroups: gmane.emacs.help Subject: Re: using setq to create lists based on other lists... Date: Mon, 3 Dec 2018 02:21:05 +0900 Message-ID: References: <5C1642CD-F485-47CF-88B9-41D7960DDE80@gmail.com> <6641A86F-1E33-44BA-8CEE-625F3213D9C4@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 (Mac OS X Mail 12.1 \(3445.101.1\)) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1543771176 32330 195.159.176.226 (2 Dec 2018 17:19:36 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 2 Dec 2018 17:19:36 +0000 (UTC) To: help-gnu-emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Dec 02 18:19:32 2018 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 1gTVP2-0008Jr-4d for geh-help-gnu-emacs@m.gmane.org; Sun, 02 Dec 2018 18:19:32 +0100 Original-Received: from localhost ([::1]:45285 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gTVR8-0002bV-NN for geh-help-gnu-emacs@m.gmane.org; Sun, 02 Dec 2018 12:21:42 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55470) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gTVQg-0002bO-NB for help-gnu-emacs@gnu.org; Sun, 02 Dec 2018 12:21:15 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gTVQc-00014q-K1 for help-gnu-emacs@gnu.org; Sun, 02 Dec 2018 12:21:14 -0500 Original-Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]:34804) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gTVQc-00013K-Bk for help-gnu-emacs@gnu.org; Sun, 02 Dec 2018 12:21:10 -0500 Original-Received: by mail-pg1-x532.google.com with SMTP id 17so4648083pgg.1 for ; Sun, 02 Dec 2018 09:21:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:mime-version:subject:date:references:to:in-reply-to:message-id; bh=/YvOOJ6lhkHV1GZGhUVOmFXHkH13UDH7vC5sl1eY/4c=; b=Kya1XUWEL5aXz2iFLZ1Aj3rLPm0l6Bza/x3fJCC/w2qQUzmUH3MpNGN6f4Sjs5s4gZ 7uL2nEjLTqAQvwQrPmIZYHa5akbmNtiPU3TFvbmTT1uhwYOAWbNCB7PESqwEP8aqsIIr BkEY3pl6c9SKUGmiiCoRL8McHsLaOyj8mW7GQiisL5DdJyxTGWJ2F51zgryM15s9kdrc KBTeT//bCD1P46/vLfwZ4AfeJPOnHadEgKRU8X/gOW6+4zT7qaCS3Ws3KhCZlH6uxo1f ahoS/t9EtZtpPBSkv1aMrFpYd1i6ZstdvjSRfCb8IcEPSjjSc9KMrmGDCnrXE/i0GWtd HKGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:mime-version:subject:date:references:to :in-reply-to:message-id; bh=/YvOOJ6lhkHV1GZGhUVOmFXHkH13UDH7vC5sl1eY/4c=; b=Nv4UXuGjM0sPJNcgX+ud4/nyUQ8n7nBYhwf4TVqZWzlp0LN+N+vRzN5IHcv1tWTwfr VltsuKSZWQ7yN2HhFl01oY3s0sKYC4KDV+bRouiLxMDrpsgHkf8iFocaZw9L15JdJB65 /hWvyH+JViNQhF5NSD7WDqlAJgBRAWVAvCSAChhieABSb88GiPwI+ly78GhwR08LNbTr WqytuN/YbgG47hDQH+A/SyEoEcR+COYDNVFdXE4W+3Dnx7+vPaA2Doa9fdeHsr+z/7ck Bvu/rcn9ySzbk7Ve9QYfBl/+R+lSrl3U587eG5cDfCu+eNxPqEe/uzl8mWCLIX4Uce4f sYrw== X-Gm-Message-State: AA+aEWbJ94Rc/KpslWUEqON5ZOv6YsHU/KovqPSEHu9TqIs68qzL2jVe 4Vxp+U4M0+vfNYkENfHlqqNO7n/7 X-Google-Smtp-Source: AFSGD/Utr45Q62O4v8Ku6s0D3wBZg+WR5dxIV7wZIynL4jNAhZb49gj47tHYMER9ZVGiIgyzvc4KQA== X-Received: by 2002:a63:9041:: with SMTP id a62mr10531424pge.163.1543771268844; Sun, 02 Dec 2018 09:21:08 -0800 (PST) Original-Received: from [192.168.1.11] (pl16832.ag0304.nttpc.ne.jp. [128.53.251.192]) by smtp.gmail.com with ESMTPSA id 6sm14523464pfv.30.2018.12.02.09.21.07 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 02 Dec 2018 09:21:07 -0800 (PST) In-Reply-To: X-Mailer: Apple Mail (2.3445.101.1) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::532 X-Content-Filtered-By: Mailman/MimeDel 2.1.21 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:118837 Archived-At: Thank you for the comments :) > You're using `setq` on vars you haven't declared/defined yet! The Introduction doesn't even mention that... > I recommend you put `-*- lexical-binding:t -*-` somewhere on the first > line of your file, and that you `M-x byte-compile RET` your file so > Emacs can help you catch some of those issues. I will. > Better write this as (setf (nth 3 myDateLastMonth) myDay) No reference to setf in the Introduction, and it's buried under tons of = reference in the Reference... Thank you again. Now I think there really is too much of a gap between = the Introduction and the Reference. The exchange today kind of confirms = that there is a need to overhaul the documentation so as to get = beginners to produce better code... Jean-Christophe=20 > On Dec 3, 2018, at 2:02, Stefan Monnier = wrote: >=20 >> I see. Eventually I used copy-tree instead to initialize the new = lists and >> then modified them separately with setcar. >=20 > So you're back to using `setcar` :-( >=20 >> Just out of curiosity, let me post what I did. There are probably >> better ways to do it, but that's the best I could come up with >> today. I'd love to be able to think in terms closer to what elisp >> allows though. >=20 > Those date/time thingies are indeed rather annoying to construct. > copy-sequence + in-place modification is probably the best you can > use, indeed :-( >=20 >> (setq now (decode-time (float-time)) >> myDateLastMonth (copy-tree now) >> myDateThisMonth (copy-tree now) >> myDateNextMonth (copy-tree now) >> now (encode-time now 'integer)) >=20 > You're using `setq` on vars you haven't declared/defined yet! > And theses aren't "trees" but lists/sequences, so better use > `copy-sequence` which is also more efficient: >=20 > (let* ((decoded-now (decode-time (float-time))) > (myDateLastMonth (copy-tree now)) > (myDateThisMonth (copy-tree now)) > (myDateNextMonth (copy-tree now)) > (encoded-now (encode-time now 'integer))) >=20 > I recommend you put `-*- lexical-binding:t -*-` somewhere on the first > line of your file, and that you `M-x byte-compile RET` your file so > Emacs can help you catch some of those issues. >=20 >> ;; create the data for last month >> (setcar (cdr (cdr (cdr myDateLastMonth))) myDay) >=20 > Better write this as (setf (nth 3 myDateLastMonth) myDay) > It's bad enough that the fields aren't named so you have to refer to > them by position, but having to count `cdr`s is really annoying IMO. >=20 >=20 > -- Stefan >=20 >=20 Jean-Christophe Helary ----------------------------------------------- http://mac4translators.blogspot.com @brandelune