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: [External] : Re: [Elisp][Question] How to modify a list by index while preserving value outside of scope? Date: Sun, 20 Aug 2023 21:45:59 +0000 Message-ID: References: <87jztqjmsz.fsf@mbork.pl> 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="22957"; mail-complaints-to="usenet@ciao.gmane.io" Cc: "help-gnu-emacs@gnu.org" To: Marcin Borkowski , Rodrigo Morales Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sun Aug 20 23:46:55 2023 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 1qXqG6-0005mL-NQ for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 20 Aug 2023 23:46:54 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qXqFU-00081R-BT; Sun, 20 Aug 2023 17:46:16 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qXqFS-000815-Ik for help-gnu-emacs@gnu.org; Sun, 20 Aug 2023 17:46:14 -0400 Original-Received: from mx0a-00069f02.pphosted.com ([205.220.165.32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qXqFP-0003Au-3c for help-gnu-emacs@gnu.org; Sun, 20 Aug 2023 17:46:14 -0400 Original-Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37KLLPvt014051; Sun, 20 Aug 2023 21:46:03 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-transfer-encoding : mime-version; s=corp-2023-03-30; bh=VS9ZizXJBTKTh0kNX5viHuY9qPqx+rfN9MxUe1GEFIw=; b=adyONnnG34Tfxge9gmHC7kONFqglaFaio45N7MQCD4kZ1wGsLR4rwMbqniUVFwkh1nii /4aWSLSsxxSe8TNoaCqNWqYWn1CQBQAsWlRI1j3nX+VaQ90VMR+thKH7Zl53GPG+kIR2 kvAQk4BQ+bXAnFftoTFKDWgKPRru4KJeUCKd8PqjmpaUFMNA3ZizrG9SuqSA8M7ebRAK Zyc6vH08lYlETihDIbYyI6fiEjaLp37h5hqX8cUlu1bU+eXYh5MN5jRcXfNt1XWcQ0nT HKgvI8Jpj7Q78boldW2BwfNMm7u6jiE0o3S2wC3N+fTD6v+W5/ux16rGJwIA0lFrSsiL bA== Original-Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3sjp9u9knj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 20 Aug 2023 21:46:02 +0000 Original-Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 37KHAdIB030399; Sun, 20 Aug 2023 21:46:02 GMT Original-Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2102.outbound.protection.outlook.com [104.47.55.102]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3sjm62rsxt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 20 Aug 2023 21:46:01 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Vfnox9x5i6M9MZv/RFROMTl31s4GNTpP79dZ242M6g5jQFRc8K689onDLR5+616dw53/jJV7b269o/wfBu+87kDcnc+IdigsmYs/ZiOl+6xfsHu0/bZj0fjbuBp9URxwpR3OIYbGARPQsNhswLvOQJPJCgAmpUmBGtRkf6J/dmB/zeH//hVa6vX/WhebKVgLdWB4MAjxxyV2GrcvjaQyTbu2jS4UBZeaUu/+SER91L/jEnBHw40uTC3YsoawZFdUpW2YFD+mtIOs9unK2a5pc6CIKvG5i/xwDTQ094aY9TpLNJZKRfLwzzUf9dPkxvfXsSNf7os4eN810oJO2Qh/PA== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=VS9ZizXJBTKTh0kNX5viHuY9qPqx+rfN9MxUe1GEFIw=; b=KWk7Dm8SoBDgwS/ONMgjkg5hHml1v8cZU8kCssKSPXg3c9GgUrCSuhxFBtPmYoyZGPtaKJ4asZgt8iURBKTONnUkbOLYh0TJONK8D1Umzc6zQ7J0XqumVRhqRbDN3tW82Tww5rYxyGJnZ4u39FM7yDmoCUgCtxAc1LR0odAsMqLDeroFhbxCfXeYy3JCeLvxp3588YplZCoXf0Qn++Dst1++QfnSklEvv5Jg2Ws7JfdNgyWyh9ZYgzWuwEBeOEyqstm4KH3i6s235cIpWzIpHtpmyIorBT+WmxPjRkUeemGfTogPyycdB+vWGribT1M33uHttm7ocvU1tVrgvYYi7w== 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=VS9ZizXJBTKTh0kNX5viHuY9qPqx+rfN9MxUe1GEFIw=; b=BJW/lUUrsM+ugvFGhs5gsCWtO/F9MxbCCA2InZ1o90sTpoVikySXgVbFBjQbgehgTnLzgNvBbAX7+udrhLbKnuz5G7zvdZGa/FwSruar+fG8oO+ayVAaXKSu/K4AaVZMddLu2Io54gIb1cGM5tPEFcM9I/5QXDf0UltEXqDCJq8= Original-Received: from SJ0PR10MB5488.namprd10.prod.outlook.com (2603:10b6:a03:37e::19) by SJ0PR10MB6302.namprd10.prod.outlook.com (2603:10b6:a03:44e::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.20; Sun, 20 Aug 2023 21:45:59 +0000 Original-Received: from SJ0PR10MB5488.namprd10.prod.outlook.com ([fe80::26ee:5721:d884:4321]) by SJ0PR10MB5488.namprd10.prod.outlook.com ([fe80::26ee:5721:d884:4321%5]) with mapi id 15.20.6699.020; Sun, 20 Aug 2023 21:45:59 +0000 Thread-Topic: [External] : Re: [Elisp][Question] How to modify a list by index while preserving value outside of scope? Thread-Index: AQHZ0yi+CP8IEu6oTEa9hc2GB4iVba/zsXRw In-Reply-To: <87jztqjmsz.fsf@mbork.pl> Accept-Language: en-US Content-Language: en-US x-ms-publictraffictype: Email x-ms-traffictypediagnostic: SJ0PR10MB5488:EE_|SJ0PR10MB6302:EE_ x-ms-office365-filtering-correlation-id: 0158c54b-1df7-48c4-1a3b-08dba1c6d755 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 79eJq4HmaLvA0psmhNsKfvj6IKXRJH2BrWDQeOocNsmiQM/BwFoCNwItpNQ1Z8pjto25BjA7qJ4WplQpUpgvnBq38+4ROX3cVgZZMUAYZUDf4k2Fzypib33XdDLPckGiDnpGNDXS4eqg3vhSGVSCwS8Fpaqrpruprf1XUb7Ew5S2/a06ZNy8K8JczZQsXTWkmmDUIQXRYX6DnC7vNKpG6RRCOIiPEwOTAPDHSuY7nZ/4mFN3hMiIe9jCC4En/CeWFDziwb5cZ5aospIgwbD9kCpfccjhXzkubEu16q23VMnvIUzF2iKGN8Xxnu/HCenJyATskdTh0jl1hhkLqr3HE04cro3PxGpuEPiBwOT5NE0TYHFTcRTUTUvD8xacgTZaGcXjyUMKGJ6bGP4hQryFUt/Lz+62fF0kiGFud1XX87nF49xeX1aHYtYoBsdwA98N1CmMj6eBeKucQzvH3x4sTlPDlYVH+HCtQNLi0m/WNhsBw8JMzrai1CY3nvdTKcsNPSspkV6q2f+VmDCPOEbSXVhSfHo1JBIOn13PzblVZevzvpfuC0hztbtcJemS4oOkTZSJyn2WX+BXDxF0TJXcoECNv9s1ynouJkTUDFvDARG+Vh9WXJptPXvitq/IPI+n x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SJ0PR10MB5488.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(39860400002)(376002)(396003)(366004)(136003)(346002)(451199024)(1800799009)(186009)(86362001)(76116006)(110136005)(64756008)(44832011)(5660300002)(33656002)(41300700001)(316002)(2906002)(66946007)(66556008)(66446008)(66476007)(8936002)(4326008)(52536014)(8676002)(478600001)(71200400001)(9686003)(38100700002)(38070700005)(7696005)(6506007)(122000001)(26005)(55016003); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?tNT+Hb8nc67CuNOVb9Y6ChYMd5fAq/62vgkLbdBiYlvzCFA2b1aCJKlmAedn?= =?us-ascii?Q?sedmX+ul66XPvkKIhqQNDh9UOf3L39MUp4+oUbcZ7Daofbmkw72GxWLDXWjJ?= =?us-ascii?Q?hR8DuebclIxS+kl4+y0aqLay2Qr9Bd50f+Rc6fvgk1iiq2n9FBx4bsxOgslS?= =?us-ascii?Q?a3ITJgj3ZMls418bHSZdAzIFI+uad09mE/JnvhGrD2wmt6QVaIuiEhCPuvid?= =?us-ascii?Q?/Rw7+hUF3opSozfk+BebSk0dfNOJx4EW/VeFnihawfXUpHiCnpJsWYgAZpoB?= =?us-ascii?Q?LtEtcBUHA8ffRXYUZRksJiIwG1gIwImaoBujy8Cx/YRoxe9ZKZUcqcwKg/qr?= =?us-ascii?Q?c2j/QAycKX1rPaIY+9sUZR66Y7aW/UivMKsRRmnbBzZICdugE5xQ5n+33zbA?= =?us-ascii?Q?9Z2nJSZ142dNamPUGy9McKnvAUR55+rWdV70NPvy3m8mYdxrOBe0UshjiIBA?= =?us-ascii?Q?XfRSw2egr5MScJkP4HxZWsQ5VCfokKdmRDzA6zbU2nYl/pNwOmI3XD/YQh2S?= =?us-ascii?Q?4V1Lf6dqBOWyrn+2L7bLmvwKdsmSoq6/WPbWYFmmS9KRHhCnTL+O4zjyeOL7?= =?us-ascii?Q?ngeCIljpku40Lz55jlmEIIGFu1IwycH9hLLqoyn47eHfS65FtGSMwy4p0z1+?= =?us-ascii?Q?+T X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: +RqUqHuSdxfmUKLDGdmyBeAKq2LBBOR8xmM8hrWEDYP4EjG8cWq8J7DdxEXcK3+R31iFxvhna7L1HI2ILqKF6Q79vybJVs2NhnSiLSbJ9m1Wu7yZK3bTPH9baDHdMKq3PUvWXx4/hCm59FMCI0/VOdCpbpbaRIwxLGFM7aSOS3rwopJeWyeThwq8cmIhSHiIwtOiuQhAqHsixqB6ZB6fA299x0SWLQYNL6PfNY7wtxf01Ql7uIrGmCVJTouOq01SYuamEDPol6bitFzDglRCPKr66l8HI6bRTWw8LtPCGeWDraF+c3/sggW/5rAUmyD5uMeQ5FZTWPWIzhI99XxG6RufYT5FbVCI/5AX08a2SovbA3cDjEgdFwrwdyB3ZEm1SVUzzLPpJjLUpg5RUazNJheFbDfIdtI4Priau2ZnlajeAJPPmrjCm+wnTqNN8mmdGFR1FR+D2pOPJwE+BTcjDbS6e1+ZQbvd81eIfOkY/mfUizKn+dB7YurBDYmBeNJw2kMXiUdou1gtj79yc4JcsYbC90+puB9MEJFrc3uiiqD8Zsn+NhcA8eOuwhjV07WTHKuoXvNKFHHt1hy4wsGx586Ly1SOAtEWGUoZZr5tWXMhRw41F6235oUXcdPsSZOwyv1mRpQpKHlwP0xR7r8Nld3mXjb97RIMjsv3L8AdGAGU7/oMAMv62qfUo5jhNwSnrnyZIBIniYL2t6Ov5XrSPozx42Bri2tnMvBE7fFS60W0cN XFt6PeHOrKCnHoFqcwUQp77vFyoLeEye39WDCF4E6dHCwd/asVA3/kYKuR/0s= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5488.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0158c54b-1df7-48c4-1a3b-08dba1c6d755 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Aug 2023 21:45:59.1103 (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: Jy7S+e9uQrKrSL1lrCOA4Tyhfwc+kFMfXUxup9csUnj3K4CBY4S/IbmJK1o2jdru3R5MzYmS62towJfbCsg6gA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB6302 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-20_15,2023-08-18_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxscore=0 spamscore=0 mlxlogscore=579 malwarescore=0 bulkscore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2308200211 X-Proofpoint-ORIG-GUID: 6B_JTZZTs2nnooef_zJnRsofMyIpTfVz X-Proofpoint-GUID: 6B_JTZZTs2nnooef_zJnRsofMyIpTfVz Received-SPF: pass client-ip=205.220.165.32; envelope-from=drew.adams@oracle.com; helo=mx0a-00069f02.pphosted.com X-Spam_score_int: -37 X-Spam_score: -3.8 X-Spam_bar: --- X-Spam_report: (-3.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_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, 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.29 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-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:144889 Archived-At: > In short: a "list" is in fact a "pointer", i.e., an "adress in memory" > where the first cons of that list lives. A NON-empty list is a cons, that is, a structure with two pointers: to the list head and its tail. An EMPTY list is NOT a cons; it's the symbol `nil', which can also be written and read as `()'. A true/proper list is one whose last tail is `nil'. A dotted list is one whose last tail is not `nil'. (It can be any value other than `nil'.) Every non-empty list can be written using dot notation: e.g., (a . (b . c)), whether or not c is nil. That's usually abbreviated as (a b . c), or if c is nil, as (a b c). > If you want to work on a "local" version of a list, you can copy that > list yourself. `append' is one way to do it; `C-h f append' tells you: The last argument is NOT copied, just used as the tail of the new list. This is important. The tail of the result is last argument. So you can't copy a list by passing it alone to `append': (let ((xs (list 1 2 3))) (eq xs (append xs))) ; =3D=3D> t But you can copy a list by appending nil to it: (let ((xs (list 1 2 3))) (eq xs (append xs ()))) ; =3D=3D> nil > `cl-copy-list' is another. Or `copy-sequence' or its alias `cl-copy-seq'. ___ You can think in terms of pointers, if that helps. But Lisp doesn't have pointers in the usual sense of the term. You can't pass explicit pointers as arguments, etc. The "pointers" are used implicitly. What's true is that when you pass a value, a _copy_ of the value is not created and passed. So yes, a pointer to the value is passed, but not explicitly - not a pointer as such. Such pointers are not values/objects in the language. In Lisp we think of the thing itself (which is a Lisp value/object) as what is passed - not a copy, and not a pointer to it. The thing _is_ its pointer (which of course is exactly what you said in your first sentence).