From unknown Fri Aug 15 04:04:13 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#42837 <42837@debbugs.gnu.org> To: bug#42837 <42837@debbugs.gnu.org> Subject: Status: 26.3; `cl-incf' returns wrong value for (alist-get 'X ALIST 0) when ALIST is nil Reply-To: bug#42837 <42837@debbugs.gnu.org> Date: Fri, 15 Aug 2025 11:04:13 +0000 retitle 42837 26.3; `cl-incf' returns wrong value for (alist-get 'X ALIST 0= ) when ALIST is nil reassign 42837 emacs submitter 42837 Drew Adams severity 42837 normal thanks From debbugs-submit-bounces@debbugs.gnu.org Wed Aug 12 17:58:40 2020 Received: (at submit) by debbugs.gnu.org; 12 Aug 2020 21:58:40 +0000 Received: from localhost ([127.0.0.1]:45743 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1k5ylb-0004As-Ih for submit@debbugs.gnu.org; Wed, 12 Aug 2020 17:58:39 -0400 Received: from lists.gnu.org ([209.51.188.17]:49374) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1k5ylZ-0004Al-MY for submit@debbugs.gnu.org; Wed, 12 Aug 2020 17:58:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58220) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k5ylZ-0001lG-Cf for bug-gnu-emacs@gnu.org; Wed, 12 Aug 2020 17:58:37 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:51236) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k5ylX-0000ge-0e for bug-gnu-emacs@gnu.org; Wed, 12 Aug 2020 17:58:36 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 07CLqHlW073610 for ; Wed, 12 Aug 2020 21:58:33 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=mime-version : message-id : date : from : sender : to : subject : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=lz5+R6NDHtapcbJ26haG771oORN91+C2vzV0ISVmdHA=; b=htYf8VcB0nS9ft+hRKfhIuPEzGmK/J5KTxj6On8ABv7wtJdfencBRnsJPe+oDQHGb0PA l4HuQTU+54aSf9R7/F/rziIx+EwcnYfnwGq/tLCV7MayhZUBY54Q1skmufM4X8TGOhtL M3xdVXnYGEO+TUXzVzPkylKmuiIPrBSsALvtktn7ByIoKuZnWf+6LR6CZlq1lJjXCM7Q IGM6B0w9VjR8ECV01kBAvC+UgFX941+qWT9hH3XTZHCkr2xx7Ubdqjp1WP03BTm2Mc5i Ku2gxiS1aSH8toEA4FUCNJnJO9RO7HV60z/kuQR68BIVEqmY2ynXWq4+wQcqjwI3pGqe BQ== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 32t2yduqvm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 12 Aug 2020 21:58:33 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 07CLqVm8057502 for ; Wed, 12 Aug 2020 21:58:32 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userp3030.oracle.com with ESMTP id 32t602a2kq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 12 Aug 2020 21:58:32 +0000 Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 07CLwUUt017538 for ; Wed, 12 Aug 2020 21:58:31 GMT MIME-Version: 1.0 Message-ID: <3f64bc3d-d22a-4910-8d1a-b2b74dd8d852@default> Date: Wed, 12 Aug 2020 21:58:30 +0000 (UTC) From: Drew Adams To: bug-gnu-emacs@gnu.org Subject: 26.3; `cl-incf' returns wrong value for (alist-get 'X ALIST 0) when ALIST is nil X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9.1 (1003210) [OL 16.0.5017.0 (x86)] Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9711 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 mlxscore=0 phishscore=0 bulkscore=0 adultscore=0 spamscore=0 suspectscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2008120140 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9711 signatures=668679 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 priorityscore=1501 malwarescore=0 impostorscore=0 lowpriorityscore=0 mlxscore=0 bulkscore=0 suspectscore=0 phishscore=0 adultscore=0 spamscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2008120140 Received-SPF: pass client-ip=156.151.31.86; envelope-from=drew.adams@oracle.com; helo=userp2130.oracle.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/08/12 17:58:33 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] X-Spam_score_int: -63 X-Spam_score: -6.4 X-Spam_bar: ------ X-Spam_report: (-6.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) `cl-incf' should always return the new value of PLACE, after it is incremented. It doesn't, if PLACE is an `alist-get' that returns the default value. (setq ali ()) (cl-incf (alist-get 'a ali 0)) returns ((a . 1)), but it should return just 1, the incremented value=20 associated with key `a'. This is the definition of `cl-incf': (defmacro cl-incf (place &optional x) "Increment PLACE by X (1 by default). PLACE may be a symbol, or any generalized variable allowed by `setf'. The return value is the incremented value of PLACE." (declare (debug (place &optional form))) (if (symbolp place) (list 'setq place (if x (list '+ place x) (list '1+ place))) (list 'cl-callf '+ place (or x 1)))) The definition should be something like this (not generally tested; might need some fixes, more hygiene, or optimization): (defmacro cl-incf (place &optional x) "Increment PLACE by X (1 by default). PLACE may be a symbol, or any generalized variable allowed by `setf'. The return value is the incremented value of PLACE." (declare (debug (place &optional form))) (if (symbolp place) (list 'setq place (if x (list '+ place x) (list '1+ place))) `(progn (cl-callf + ,place (or ,x 1)) ,place))) IOW, after updating the alist entry, `cl-incf' needs to return the new value for the given key. `cl-callf' currently returns the entire alist. See this question from user `grepcake', who uncovered the problem: https://emacs.stackexchange.com/q/60097/105 In GNU Emacs 26.3 (build 1, x86_64-w64-mingw32) of 2019-08-29 Repository revision: 96dd0196c28bc36779584e47fffcca433c9309cd Windowing system distributor `Microsoft Corp.', version 10.0.18362 Configured using: `configure --without-dbus --host=3Dx86_64-w64-mingw32 --without-compress-install 'CFLAGS=3D-O2 -static -g3'' From debbugs-submit-bounces@debbugs.gnu.org Thu Aug 13 11:55:33 2020 Received: (at 42837-done) by debbugs.gnu.org; 13 Aug 2020 15:55:33 +0000 Received: from localhost ([127.0.0.1]:50736 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1k6FZl-0004vi-Ic for submit@debbugs.gnu.org; Thu, 13 Aug 2020 11:55:33 -0400 Received: from mail-yb1-f170.google.com ([209.85.219.170]:37311) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1k6FZj-0004vS-EW for 42837-done@debbugs.gnu.org; Thu, 13 Aug 2020 11:55:31 -0400 Received: by mail-yb1-f170.google.com with SMTP id e14so3583312ybf.4 for <42837-done@debbugs.gnu.org>; Thu, 13 Aug 2020 08:55:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:in-reply-to:references:user-agent :mime-version:date:message-id:subject:to:cc; bh=F3h95hCqyn5f8d0CKvDcVzlOnsXspSYjaSPmgY357r4=; b=UKvppojnoZdRajxoO0mxNgLQv4YRkzPSjQXqZZAcmPu2BNuz71DVmdNglVFBBFPNP8 4vtDDgnxkzBjlANoClxxQM02690K/N0nUlFw5LnBLwzDtRGU0VKSdBgEfivXdt6GNoSh jQmpKn+F651w08EAvhVJmRunqIVE0v84/TCCJGg4DCzWtuaD5UQxmIQD9fImOVpIk/bs ytolDRe7G3iZAwoAu/yDL2sYv7TfK20CpecI+TDYpeLuTB9FTIFs2QoposJEUb2YODgh W3dVnRqrQways0Y0KkTqb1rmhjiUH1wwlUTgfMamq+uGgg1iAt/VZ72E3psH2wBVF1rO p2gQ== X-Gm-Message-State: AOAM5320AUdppj54lWQheWf65tpIqOLphTsye6/XE6E/XSFtuXFI+cBf ogjPM+2brPkqYoMZKZPnzXK+xERTf2ojGJUxFWw= X-Google-Smtp-Source: ABdhPJytyU+TyTifaigzumxhuAto0YdC7F5ADcR/o/HwVgAUzBa/LZW04XzvZSdZGpa7Bq34wBXZpR9EV96kJioZk2k= X-Received: by 2002:a25:b88b:: with SMTP id w11mr7913230ybj.129.1597334125820; Thu, 13 Aug 2020 08:55:25 -0700 (PDT) Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Thu, 13 Aug 2020 08:55:25 -0700 From: Stefan Kangas In-Reply-To: <3f64bc3d-d22a-4910-8d1a-b2b74dd8d852@default> (Drew Adams's message of "Wed, 12 Aug 2020 21:58:30 +0000 (UTC)") References: <3f64bc3d-d22a-4910-8d1a-b2b74dd8d852@default> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) MIME-Version: 1.0 Date: Thu, 13 Aug 2020 08:55:25 -0700 Message-ID: Subject: Re: bug#42837: 26.3; `cl-incf' returns wrong value for (alist-get 'X ALIST 0) when ALIST is nil To: Drew Adams Content-Type: text/plain; charset="UTF-8" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 42837-done Cc: 42837-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Drew Adams writes: > `cl-incf' should always return the new value of PLACE, after it is > incremented. It doesn't, if PLACE is an `alist-get' that returns the > default value. > > (setq ali ()) > > (cl-incf (alist-get 'a ali 0)) > > returns ((a . 1)), but it should return just 1, the incremented value > associated with key `a'. I can reproduce this on Emacs 26.3 (under emacs -Q). But it seems to have been fixed on emacs-27 and current master, where I get: (progn (require 'cl-lib) (setq ali ()) (cl-incf (alist-get 'a ali 0))) => 1 I'm therefore closing this bug report. Best regards, Stefan Kangas From unknown Fri Aug 15 04:04:13 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Fri, 11 Sep 2020 11:24:06 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator