From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.help Subject: Re: Appending lists Date: Thu, 17 Jun 2021 03:18:48 +0000 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4532"; mail-complaints-to="usenet@ciao.gmane.io" To: Emanuel Berg , "Help-Gnu-Emacs (help-gnu-emacs@gnu.org)" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jun 17 05:19:22 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ltiYs-0000z3-5f for geh-help-gnu-emacs@m.gmane-mx.org; Thu, 17 Jun 2021 05:19:22 +0200 Original-Received: from localhost ([::1]:48766 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ltiYq-00015P-HI for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 16 Jun 2021 23:19:20 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41220) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltiYU-00015G-6p for help-gnu-emacs@gnu.org; Wed, 16 Jun 2021 23:18:58 -0400 Original-Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]:55592) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ltiYR-0003BF-Nz for help-gnu-emacs@gnu.org; Wed, 16 Jun 2021 23:18:57 -0400 Original-Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 15H3CeWj007593; Thu, 17 Jun 2021 03:18:52 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : content-type : content-transfer-encoding : mime-version; s=corp-2020-01-29; bh=0z6NIQ5O9mRVMqmuw/3w6Bf36d/i+JrrluJoqGqZ9k8=; b=NKPU0JPY4V6wO91QbwbO8IPIz/Mu79PHM8c864VBlLhSbv+lKSpnuF+drB2u3WiyZrQ1 Vmi1ebnPxDQihnvZP+w9jbFr+rf2y/mWlJHkVGCVaQj0uWTkDs15iCSvVMZ2U3W12MLM Vyx0FMVsyUtDStuzxMFs8trVQvTH+pyd1c388ossYKwvbXEC6KpqUvqugj1KTiPdn/nt Z0MJb5U1k1jbtqH6DzZwVjIYqcRH78xcOxuDh/rGNhnBpZwzbeIale5m9G0OfKaCUSgp fCihR6Xd9jElXUrOUEBgM9oKvZs4n/QfSO/SGk5/VwusFz4Cz69F0Hd0BDYJgWoLtB20 fA== Original-Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by mx0b-00069f02.pphosted.com with ESMTP id 397mptguhb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Jun 2021 03:18:52 +0000 Original-Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 15H3BKVs113007; Thu, 17 Jun 2021 03:18:51 GMT Original-Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2172.outbound.protection.outlook.com [104.47.56.172]) by aserp3030.oracle.com with ESMTP id 396wav2kmp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 17 Jun 2021 03:18:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jB8HxD/OQP23pz8OXaNoRWA2ENH+M3hodXTbDsnxqtjBeQIpZSS6SYXd4tJF5FcAAp2C1fAOPe2pMm1VQC9Wm9GAYW/ESIW5t5XR7tnb7a2oJlSXDxW1ltQpr1oGsxdfUTZa+Kq06XcFAvq1x3ycQtGcz0DPNh3RA/kV4EsqLN4Rr+nTIzzIlCZmyUNr18Hr19xTzLz8ahmGyQBBKHzDEAhb+XuSsk40nLyNb4TAVoAKjz1+vcaYfdViTaPJiBHmW68/g4tw2ge0dnJfBEybq+B+1c1gZ03FGjmrON1jDTHFPz0zaQvqYdwzoEO70UXlyXEId/Fks77HgYdd0nxelQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0z6NIQ5O9mRVMqmuw/3w6Bf36d/i+JrrluJoqGqZ9k8=; b=JLzqxT3Aplz46aXZPnzKM0jUNz/a5bH0nC2RwUmks7Bld5HxRq28C4/E4Q2YySiok/ikfvw7EQAtuaAeI+SCf/wOZ4c+H0gH/qBUH47FPyCi5U99DuXK3n3CSCx4WTKzaXUWYZF32HlzYH2EteuYNijAEiD9jnw0TR139FqMsbBTKixAvyPJhaiT9wjDLQSpji65XKVlMWREvntOmzssK9LyUGGJBxtUVKiMy4mE7FOlx3+liXmCczsvIsy8QWF+f4w7z/0lqHIgS8xBYOhZ3h9TaOsoeGocCPP+rlsEYQrQ4Ns9HtuTMol/oghz7LKn+WYMi7apN3jrxu6tNEVsqA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0z6NIQ5O9mRVMqmuw/3w6Bf36d/i+JrrluJoqGqZ9k8=; b=spYg4heVpIWNPsTp2uatcD3sDGrQy3sctuZymxPMH0zwj6YLOBWT8Us7UsYsk7c6U33E7G9wp8g9ZIMEVOLaLLDSQQ/napw5FTsamaCFUDp1tD3L2bHgBKHzKj+aDzdzpzQDt7hiPfoHwjMakl7wn3ylmpf2ETyNu/uviG6Ytlo= Original-Received: from SA2PR10MB4474.namprd10.prod.outlook.com (2603:10b6:806:11b::15) by SN6PR10MB2432.namprd10.prod.outlook.com (2603:10b6:805:46::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4242.16; Thu, 17 Jun 2021 03:18:49 +0000 Original-Received: from SA2PR10MB4474.namprd10.prod.outlook.com ([fe80::1c0e:6d54:3781:bd5c]) by SA2PR10MB4474.namprd10.prod.outlook.com ([fe80::1c0e:6d54:3781:bd5c%6]) with mapi id 15.20.4242.019; Thu, 17 Jun 2021 03:18:49 +0000 Thread-Topic: Appending lists Thread-Index: AddjJ3x77eGo6FdCTq+WMgj+UHI7Kg== Accept-Language: en-US Content-Language: en-US authentication-results: zoho.eu; dkim=none (message not signed) header.d=none;zoho.eu; dmarc=none action=none header.from=oracle.com; x-originating-ip: [73.170.83.28] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 8fb853ee-28b5-4117-d2e7-08d9313e9fe9 x-ms-traffictypediagnostic: SN6PR10MB2432: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8273; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: EAN1j/+b9gxMeVWhFNxrPPn0qQNdqa7KXGVsCTWJI4l1eB2pxdFzYp1ZmzSbygvFBP7/Nt7cH2cOox8xzKQsBZa+bqVQgOFv2UkKoWiAHbQnb9imDpqKdms6Ye9rfax/IeZ1tIoC3l2BcbB0iOXAHR+I8QSFVyxhs6blGvKHraq8tOyNT04oq9BW/tTH1QnxizrKOtSFcTEfp+8bCG4W83QNdv4KJDDcoLkYSm1HJF1tl/7RaD6QMkBTCCFkX3DDErjsPGTo4GoMdOYl2Qe/laKuFqlQXua7/I8kspbkP73roVt+JT8ae1Jk7FkgDyPYNgW4GiVef2VnqvIF4P6R7jzpY+OiEyGAsZuSFy/8Lc01FJGx2KTxhzcY87e/5AZhaAUfRtTxECuAzSCz3VA0CjiOoFB967plD6ctyC/0jrBYOaSa1TYNtY2psGQV1qFpVKs5be0PKfnjAlg3/Kx2KXBGb6quFYET4+z/5l1Kbf6cUjZCzWVnsqUZs1V4XoM+r+z1X6LEX0A7m8GUw2JlyK7cXEBu1mafyjFC3H1QZ62IgMVowIqjDCj8TZDW+IOC4YSQR7nbvdcUZSD0tR57H/riuEosFREISGBGzMSKYAMId771URNfkxFe3mXowxuLJfI2n9h/PhhItuT5mRUx12+pQkhsGvb6WDrQjlfirx0= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SA2PR10MB4474.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(396003)(136003)(376002)(346002)(39850400004)(366004)(478600001)(7696005)(55016002)(83380400001)(8936002)(5660300002)(8676002)(186003)(7116003)(26005)(66446008)(86362001)(64756008)(66476007)(66556008)(71200400001)(66946007)(316002)(3480700007)(6506007)(33656002)(122000001)(76116006)(9686003)(52536014)(110136005)(38100700002)(2906002)(44832011)(180763001); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?grSQz+ikC3whSdITsZxua5Xdflq9Ni5UsP9+3uFtTIEbB9mevFv5PdNIw60q?= =?us-ascii?Q?RyB20HX2tQjwjiMYeMyAymzz9D80joMpffSIvBLcOtuLa7BnASot7zzh7xnV?= =?us-ascii?Q?wH0bDgtb4vRqDP+3S61Bj9ouvGrgg3PXiRdPML9g0MRCr7p+oPgJid471G/C?= =?us-ascii?Q?tuCMpnwFNdimIuJ+zqNL+lqDLIDc66QM3HNz2VTtHEC9AklcJ+yX5aiCILxF?= =?us-ascii?Q?5FnEeosOd0LSm0bzgzWUV+qk6PqTLF9rlfY+numbFUSZaNJSqTl0rgt9XeSN?= =?us-ascii?Q?HW9pToXKzSfpf+KoF5H5UnqScOxGYgDgkzOYvlqYZI1+QjU60qxvs+bLG+4P?= =?us-ascii?Q?ayqioy7IvLee0ctjnmjCOyldpt1K5KHClcXL+5pIC6y1GqOSB8sDkJiWmSHH?= =?us-ascii?Q?i1syCUBrbiA6lCPF67Ml4BPhZ8m+q1kNYizZVY/D16hrRuDxpjCyNlGkawmL?= =?us-ascii?Q?5F/+Efa270eTGbK514qHKGYNAIyOck94SxNlUqdeWRNNnPydTo35q2GKWFyb?= =?us-ascii?Q?8UU8HYFcW2BZ3VKj1p/sYMzQy07qOH8MSjDkc/SvMmgiOosOpRQxyDUmS9uh?= =?us-ascii?Q?6N165IbqQE5nYhF5KDLXbKMQFTEBkn81NtX7QMgwz7Sfx3iqVjTZ+00DrQi8?= =?us-ascii?Q?G7 x-ms-exchange-transport-forked: True X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: SA2PR10MB4474.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8fb853ee-28b5-4117-d2e7-08d9313e9fe9 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Jun 2021 03:18:48.9075 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 9Z7Fj7GKgmEm4i+gTSFLDcWzdmjudxmYPd21ihmBvXq/jJLRvCii3pHs86jey60ArIACA5wHFaZB6X8jVGrDqA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR10MB2432 X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=10017 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 suspectscore=0 mlxlogscore=460 bulkscore=0 mlxscore=0 spamscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2106170019 X-Proofpoint-GUID: iN5pz1hQdLmafuhMlLLomxAnweN3WflW X-Proofpoint-ORIG-GUID: iN5pz1hQdLmafuhMlLLomxAnweN3WflW Received-SPF: pass client-ip=205.220.165.32; envelope-from=drew.adams@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 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-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:130949 Archived-At: > >> What's a "deep copy"? > > > > It's a copy where every part of the object is separate, not > > `eq' to the corresponding parts of the object that > > you copied. > > > > For a cons, which is a tree, it would mean that neither car > > nor cdr are shared between the original and the copy, and > > that the same is true for any cars and cdrs that are, > > themselves, conses. > > > > IOW, the tree is separate/independent from its copy. > > When that's the case you can change any parts of either > > without affecting the other. > > > > `C-h f copy-tree' describes the difference between what it > > does (a deep copy) and what `copy-sequence' does (shallow > > copy - doesn't copy cars. >=20 > deep copy =3D actual copy > shallow copy =3D copy of references? Did you read `C-h f copy-tree'? No. Everything involving list structure (conses) uses references. `copy-sequence' is a shallow copy - it copies only the conses that make up the cdrs, so that you get new conses for ONLY those - just the conses that make up the _sequence_). It copies only the flat, cdr list structure, not any list structure in cars. You get a new sequence, but the sequence elements (the cars) share list structure with the input sequence. E.g., `copy-sequence' on the list `((1 2) 3 (4))' gives you a new sequence (list) whose elements are also `(1 2)', `3', and `(4)'. The first and third elements are not only `equal' to those of the input sequence - they are `eq' to them. `copy-tree' is a deep copy - it copies conses in both cars and cdrs, so you get new list structure (conses) everywhere. There is NO cons in the output that's `eq' to a cons in the input. The result of `copy-tree' is a new `((1 2) 3 (4))' list a new tree through and through. Its first element, `(1 2)' is not `eq' to the `(1 2)' of the input list. Same thing for its last element. `copy-tree' results in a list that's `equal' to the input list, but there is no cons in it that's `eq' to a cons of the input. `copy-sequence' guarantees that conses in cars of the output sequence ARE `eq' to those in the input. (setq foo '((1 2) 3 (4))) (setq sfoo (copy-sequence foo)) (eq foo sfoo) ; nil (eq (car foo) (car sfoo)) ; t (eq (caddr foo) (caddr sfoo)) ; t (setq tfoo (copy-tree foo)) (eq foo tfoo) ; nil (eq (car foo) (car tfoo)) ; nil (eq (caddr foo) (caddr tfoo)) ; nil `copy-tree' is more expensive. `copy-sequence' lets you continue to share sequence elements. If two lists share any parts, then if you change such a shared part in one it's changed also in the other. That's exactly the point of sharing. It's also the "danger". Don't share List structure unless you intend to. You may never need to or want to. You will need to be aware of list structure and the possibility that it gets shared, when playing with Lisp code that you didn't write, at least. And know about Lisp functions that can catch you up on this kind of thing - functions called "destructive" in the doc, i.e., functions that can modify or share list structure. ____ [If you happen to know Fortran then think COMMON blocks plus overlapping DIMENSION specs: shared bits of overlapping memory, like Venn diagrams. Programs can act on different bits in different ways. Many large Fortran programs were all about this sort of thing. Likewise some assembler programs.]