From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.help Subject: RE: replace element in list Date: Wed, 21 Nov 2018 21:39:11 -0800 (PST) Message-ID: <45a3b5b6-2985-4eab-bb2c-2ad9b4459018@default> References: <2087821187f90948d25d93c7ea475e66@openmail.cc> <87zhu1y9k1.fsf@ericabrahamsen.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1542865112 19656 195.159.176.226 (22 Nov 2018 05:38:32 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 22 Nov 2018 05:38:32 +0000 (UTC) To: Eric Abrahamsen , help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Nov 22 06:38:27 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 1gPhh3-0004rz-Nr for geh-help-gnu-emacs@m.gmane.org; Thu, 22 Nov 2018 06:38:25 +0100 Original-Received: from localhost ([::1]:44103 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPhj4-0005o4-RM for geh-help-gnu-emacs@m.gmane.org; Thu, 22 Nov 2018 00:40:30 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36344) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPhiP-0005nn-VM for help-gnu-emacs@gnu.org; Thu, 22 Nov 2018 00:39:50 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gPhiK-0005Ib-PO for help-gnu-emacs@gnu.org; Thu, 22 Nov 2018 00:39:49 -0500 Original-Received: from userp2130.oracle.com ([156.151.31.86]:45564) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gPhiK-0004X6-C7 for help-gnu-emacs@gnu.org; Thu, 22 Nov 2018 00:39:44 -0500 Original-Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id wAM5dEli151395; Thu, 22 Nov 2018 05:39:14 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=mime-version : message-id : date : from : sender : to : subject : references : in-reply-to : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=mb6EvuzM8VrTF4ZkJ94N6OIxB+hvEAKbKepUGTzLpnA=; b=emUcPa5xpfr7X0RskJWKtDZVmhsQF5wGL6uLq+xlh85sCHzV0EK6CRgQcu8wrPM3Sa+K rZtNag2AEsHUkRyB9NgnMXIUWgWJ9nKecXTkkCRwhgVwz02YhbOiFkj93ZKey5POH/Pw bVkFJsAzPS5Kkcal0r9JdO72GvdxKBR9NISqWViNDD50hRXlunJkpTjSxBezcemX+SfC 5CgCnsmoeNCWUA9Px7tDpEzy28INK+YgY4uRF9v2eaWGIqY/R6dZLOn/57pCm4dd4BS0 LuyRtZe/4vqLyuLxGuB/8j/w9aAbLIHaSlNt8yH3sFJ48fvvQWOmR6u69ZdAYGb0nZv3 wQ== Original-Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2130.oracle.com with ESMTP id 2ntadu4y84-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 22 Nov 2018 05:39:14 +0000 Original-Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id wAM5dD2r017268 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 22 Nov 2018 05:39:13 GMT Original-Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id wAM5dCKg018683; Thu, 22 Nov 2018 05:39:12 GMT In-Reply-To: <87zhu1y9k1.fsf@ericabrahamsen.net> X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 16.0.4771.0 (x86)] X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9084 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=597 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1811220053 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 156.151.31.86 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:118728 Archived-At: > > (defun my-list-replace (obj orig new) > > "Replaces an element in a list with something else" > > (let* ((pos (cl-position orig obj :test 'equal)) > > (pos (if pos pos 0)) > > (objlen (length obj)) > > (head (butlast obj (- objlen pos))) > > (trail (nthcdr (+ 1 pos) obj))) > > (append head (append new trail)))) >=20 > (let ((orig '(("a" . "b") ("c" "d"))) > (obj '("c" "d")) > (new '(":)"))) > (setf (nth (cl-position obj orig :test #'equal) orig) new) > orig) (defun toto (xs old new) (let ((ms (member old xs))) (unless ms (error "%S is not in %S" old xs)) (setcar ms new) xs))