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: Sun, 2 Dec 2018 21:03:04 +0900 Message-ID: References: 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 1543752100 30837 195.159.176.226 (2 Dec 2018 12:01:40 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 2 Dec 2018 12:01:40 +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 13:01:36 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 1gTQRM-0007vD-Co for geh-help-gnu-emacs@m.gmane.org; Sun, 02 Dec 2018 13:01:36 +0100 Original-Received: from localhost ([::1]:44245 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gTQTO-0000sd-7W for geh-help-gnu-emacs@m.gmane.org; Sun, 02 Dec 2018 07:03:45 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55384) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gTQSx-0000lw-F6 for help-gnu-emacs@gnu.org; Sun, 02 Dec 2018 07:03:16 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gTQSt-0000IG-Cs for help-gnu-emacs@gnu.org; Sun, 02 Dec 2018 07:03:15 -0500 Original-Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]:45810) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gTQSr-0000Ho-GF for help-gnu-emacs@gnu.org; Sun, 02 Dec 2018 07:03:11 -0500 Original-Received: by mail-pl1-x635.google.com with SMTP id a14so5016354plm.12 for ; Sun, 02 Dec 2018 04:03:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:content-transfer-encoding:mime-version:subject:date:references :to:in-reply-to:message-id; bh=zwz9jykgD/9kE2ZU7gtYnUX5U45482gZXiPd5zAeO9o=; b=crLNFerq6wR/uhHRFWCQQAKMfX1v4r4s4OLUO3K216DpCj6A7Z7LS+h0QsdIz77/Lx uRhaUDwyJ4nLu3NcaXBe4GciMiw395ew9l5GDryvZ7bDQAQdyTCjng77Y/zEnI3Or8th MI8BqvAmz2QJWsAOKmOVfEszY9Wv92eLSWLeif/CVhmPMWgDLz1fHK/VN5NDyPndThE9 PSI1uixfUhZLpBxEKH1uHBl0nk9ATZBjBoUHxGD2hjsOmUrTlxwwhpuCtptzuLycXf+m PgOQy7saGPxlqD4b+ekPV8DbgqnY8GLOWy69GfTC0A0SC/8CPTS1O82njqgBQ21UaoSj iTdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:content-transfer-encoding:mime-version :subject:date:references:to:in-reply-to:message-id; bh=zwz9jykgD/9kE2ZU7gtYnUX5U45482gZXiPd5zAeO9o=; b=oyoRgrs/Yc9kfkDmK8u09o0DSLWpSHrgfO4vEGpEAjNyoJ6+9xCeVTkeFA3tnmySpl 4eYT9YCzquB39skwJwAUOhdUbeTvZYL6KBT/XeOBOKBwbCXYf7PjWLH8n8EZbI2I+M04 EtzfZWi8FWHvThFKEatxZs92MZaJqwrAnuP49+9z88/TWvK/1f20tyurC8G24115gaCq c/MkgF8Wz0LZTyHcK2Mv2409fg0UWqSTmmSBsg22nJ3chaS5U5ERuOhLtiGCVDfKpKB8 m05QieUrZUSoSZxAcGo0syC91l8pgy4wVUMPm3a4cXph6mvC0Ey3SrXP5B9qwQjs9jOn rocg== X-Gm-Message-State: AA+aEWaIo06g4jQs4owwqBZVeJzym6YyZGUq62z7rFZAJ+yDKCyBmV3X OrfzrqPRSnmarltBebRf6CwEkRm2 X-Google-Smtp-Source: AFSGD/Vw5wVTlVnzmSnPpiY8d9EgPR3111rHvXXs2uRIQm21WHFG7EaXY2trn75MqKl0sBLnz9E0gQ== X-Received: by 2002:a17:902:59c8:: with SMTP id d8mr12207287plj.116.1543752187856; Sun, 02 Dec 2018 04:03:07 -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 t2sm18333710pfm.32.2018.12.02.04.03.06 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 02 Dec 2018 04:03: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::635 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:118822 Archived-At: Barry, thank you for the reply. > On Dec 2, 2018, at 20:21, Barry Margolin wrote: >=20 >> I spend most of the day investigating why creating a list with setq = was not=20 >> "working". >>=20 >> For ex: >> (setq list0 '(1 2)) >> (setq list1 list0) >>=20 >> If you do >>=20 >> (setcar list0 0) >>=20 >> then for some reason (for which I could not find an explanation in = the elisp=20 >> reference) the car of list1 also changes, and vice-versa. >>=20 >> Which is totally unexpected since when you do: >>=20 >> (setq list0 0) >>=20 >> list1 does not become 0 >>=20 >> I don't suppose that's a bug, but really it ought the be very clearly=20= >> documented in the reference. Also, I'd like to know why that's = happening. >=20 > list0 and list1 both contain references to the same cons. The reference says: > Note that the first form is evaluated, then the first symbol is set... So in my case I expected to have list0 evaluated to (1 2) and list1 set = to (1 2). You mean that list0 evaluates to a pointer to a cons that holds the = values (1 2) and that list1 is set to that pointer. I'm ok if that is true but I wish it were plainly written in the = reference. Because I can't find a place where it is clearly written that = lists evaluate to a pointer to their cons. > If you're familiar with C, you can think of Lisp variables as being = like=20 > pointers, and conses are like structures. Your code is equivalent to: I am not familiar with C but think you for the explanations. > cons *list0 =3D malloc(sizeof(cons)); > list0->car =3D make_number(1); > list0->cdr =3D malloc(sizeof(cons)); > list0->cdr->car =3D make_number(2); > list0->cdr->cdr =3D null; > cons *list1 =3D list0; > list0->car =3D make_number(0); Jean-Christophe Helary ----------------------------------------------- http://mac4translators.blogspot.com @brandelune