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 01:23:25 +0900 Message-ID: <6641A86F-1E33-44BA-8CEE-625F3213D9C4@gmail.com> References: <5C1642CD-F485-47CF-88B9-41D7960DDE80@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=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1543767719 28804 195.159.176.226 (2 Dec 2018 16:21:59 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 2 Dec 2018 16:21:59 +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 17:21:55 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 1gTUVG-0007NP-JE for geh-help-gnu-emacs@m.gmane.org; Sun, 02 Dec 2018 17:21:54 +0100 Original-Received: from localhost ([::1]:45058 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gTUXM-0001a5-SY for geh-help-gnu-emacs@m.gmane.org; Sun, 02 Dec 2018 11:24:04 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45779) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gTUWt-0001Zk-5J for help-gnu-emacs@gnu.org; Sun, 02 Dec 2018 11:23:36 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gTUWo-0000UW-8Y for help-gnu-emacs@gnu.org; Sun, 02 Dec 2018 11:23:35 -0500 Original-Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]:41602) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gTUWn-0000UA-WC for help-gnu-emacs@gnu.org; Sun, 02 Dec 2018 11:23:30 -0500 Original-Received: by mail-pl1-x62c.google.com with SMTP id u6so5178879plm.8 for ; Sun, 02 Dec 2018 08:23:29 -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=y94DQX5eRqII6E/Bl/FFE2A8jNF7YaT1dB6FXR1GTqc=; b=t7WV76F2YW+ZJ8d+YGsfaO9tPzJW1EqVE6wie9CK1UjlBNmdoZ0sCMRYobsQY52Cb3 3K2gedXI+PaMDxemKg1ifPDUUNVKIG3gJ1u4qC4NI1DHnEYIq66c7IpTr2vi3WQr+m5i AbZFkR4OdVUvZAEPSQs4CzoItUoiL3lIczAUM87DGWBeYoWipjDsLDHqC4mFFVbpcDZa tbd7equWV8yhcgOyS+t9/Iok5t6zDx3tu/EgiStr+nUonSH9/xTh14HkPX4GfP7aJ1pV mXoNAPR8ZsTaPGj4Jmh+ISy9LXRGPtCqsyog2IRL+lXBZ5r4m45OLLV8tFKpTcjS/z4T 5jDA== 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=y94DQX5eRqII6E/Bl/FFE2A8jNF7YaT1dB6FXR1GTqc=; b=RFI9lCRXvTDkC1VQOxAAtHitwTADoSaHsrwLq4Lnf1k9+I2tcCi7j/9hzEtRpSYel3 W+uDg7IVHHTNn6LBFdT9um6XQm5btTQJWU1fyXRoM+ltbUpVCtCY6Cgx727dcE+tIgwO DD2mC75JE4pRpjZ0TAX7GNKNsHJXlHOroTIHl2r2HuZ8OoNpGNirke9oiK4BnF4zERY7 qPZdHS+Y3uKtLOXVwMsOcErjgMUAzTBjOqUmYwALGuGXuV1Dv12ERBuLYowLSNXmnixV JkN23tKmtqqOVg4wzAU89FpysW1s8Hf8M3aNQ6BR1d02HP1Db7RMsvaNFEbufNJuyMhu DYQg== X-Gm-Message-State: AA+aEWas9mzwoPOfbyj4P9TjNazPixngNvLWjdZEaP79L4CWemnDra87 1Lnq9zDczQe0S8LIboKh7dbl5N0h X-Google-Smtp-Source: AFSGD/V3vV5btttqknx15HA17bm8heVMjVs1MeRWkOq0eB51rWLBv6xjruLTOBrkoamHBS8MGFDZsA== X-Received: by 2002:a17:902:b093:: with SMTP id p19mr3982579plr.135.1543767808445; Sun, 02 Dec 2018 08:23:28 -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 w184sm12827655pgd.34.2018.12.02.08.23.26 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 02 Dec 2018 08:23:27 -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::62c 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:118835 Archived-At: > On Dec 3, 2018, at 1:05, Stefan Monnier = wrote: >=20 >> When I check "Modifying Existing List Structure" the only things I = find of >> any use in my case are setcar/setcdr. >=20 > That's because "modifying" is the wrong way to think about it. >=20 > That section should start by telling the user that most likely what = they > really want to do is something else (i.e. get a similar list structure > with some differences). I see. Eventually I used copy-tree instead to initialize the new lists = and then modified them separately with setcar. >> I would certainly have considered that if I had known that setq was >> linking the lists :) >=20 > Clearly, "linking the lists" means something to you, but it means > nothing to me, so the manual can't really say something like that. I think somebody used that term in the thread. I didn't even have that = concept before the discussion started :) 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. Jean-Christophe Helary ----------------------------------------------- http://mac4translators.blogspot.com @brandelune ;; The function takes a date d and returns a (d m y) list where (d m y) = is the closest day to today ;; For ex, today is 2018/12/3 ;; d=3D1 -> (1 12 2018) ;; d=3D30 -> (30 11 2018) ;; d=3D15 -> (15 12 2018) ;; I use the function in a template for a blog that I write one page a = day. ;; When I launch the template for a given day, it creates links for the = previous day and the next day ;; I used the "closest" assumption because I'm either writing the blog = late, or outputing future days templates for preparation. (defun getMyDate (myDay) (interactive) (if (or (> 1 myDay) (< 32 myDay)) (setq myDay (nth 3 (decode-time)))) (setq now (decode-time (float-time)) myDateLastMonth (copy-tree now) myDateThisMonth (copy-tree now) myDateNextMonth (copy-tree now) now (encode-time now 'integer)) ;; need to create "last month", "next month", "last year", "next year" ;; 1 day is 84600 seconds ;; 1 month is approximately 2,592,000 seconds ;; 1 year is approximately 31,536,000 seconds (setq yesterDay (nth 3 (decode-time (- (float-time) 84600))) ;; not = used in the function toMorrow (nth 3 (decode-time (+ (float-time) 84600))) ;; not = used in the function lastMonth (nth 4 (decode-time (- (float-time) 2592000))) thisMonth (nth 4 (decode-time)) ;; not used in the function nextMonth (nth 4 (decode-time (+ (float-time) 2592000))) lastYear (nth 5 (decode-time (- (float-time) 31536000))) thisYear (nth 5 (decode-time)) ;; not used in the function nextYear (nth 5 (decode-time (+ (float-time) 31536000)))) ;; create the data for last month (setcar (cdr (cdr (cdr myDateLastMonth))) myDay) (setcar (cdr (cdr (cdr (cdr myDateLastMonth)))) lastMonth) (if (=3D lastMonth 12) (setcar (cdr (cdr (cdr (cdr (cdr myDateLastMonth))))) lastYear)) ;; create the data for this month (setcar (cdr (cdr (cdr myDateThisMonth))) myDay) ;; create the data for next month (setcar (cdr (cdr (cdr myDateNextMonth))) myDay) (setcar (cdr (cdr (cdr (cdr myDateNextMonth)))) nextMonth) (if (=3D nextMonth 1) (setcar (cdr (cdr (cdr (cdr (cdr myDateNextMonth))))) nextYear)) ;; compare the dates to find the closest (setq a (abs (- now (encode-time myDateLastMonth 'integer))) b (abs (- now (encode-time myDateThisMonth 'integer))) c (abs (- (encode-time myDateNextMonth 'integer)))) (if (and (< a b) (< b c)) (setq myMonth (nth 4 myDateLastMonth) myYear (nth 5 myDateLastMonth)) (if (and (< b a) (< b c)) (setq myMonth (nth 4 myDateThisMonth) myYear (nth 5 myDateThisMonth)) (setq myMonth (nth 4 myDateNextMonth) myYear (nth 5 myDateNextMonth)))) ;; et voil=C3=A0 (list myDay myMonth myYear)) (getMyDate 30)