From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Augusto Stoffel Newsgroups: gmane.emacs.devel Subject: Re: Improve `replace-regexp-in-string' ergonomics? Date: Wed, 22 Sep 2021 10:14:56 +0200 Message-ID: <8735pxjabj.fsf@gmail.com> References: <878rzpw7jo.fsf@gnus.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22966"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: emacs-devel@gnu.org To: Lars Ingebrigtsen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Sep 22 10:16:55 2021 Return-path: Envelope-to: ged-emacs-devel@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 1mSxQy-0005bN-Cq for ged-emacs-devel@m.gmane-mx.org; Wed, 22 Sep 2021 10:16:52 +0200 Original-Received: from localhost ([::1]:57554 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mSxQv-0006Mj-Ss for ged-emacs-devel@m.gmane-mx.org; Wed, 22 Sep 2021 04:16:49 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49788) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mSxPE-0004xx-Ee for emacs-devel@gnu.org; Wed, 22 Sep 2021 04:15:04 -0400 Original-Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]:37510) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mSxPA-0003Hb-PK for emacs-devel@gnu.org; Wed, 22 Sep 2021 04:15:04 -0400 Original-Received: by mail-wr1-x429.google.com with SMTP id t8so4286432wrq.4 for ; Wed, 22 Sep 2021 01:14:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=FteSFK9+97P2dFFwwOOZ3FBdYgQVfdGi6UPMpkEohYE=; b=hMi+GYRy120+FZYl7CK+tehotF63rMXtrt8k4xk2R8hCz4S+WKtAGqniPPCtf+z3Q9 erQOzhUSoMQyn/nWAnljN6CNX5s4hcV7m2OzmzTJqQ6VVx8zLLO1f64nvJgIwonJ6+q5 L6JrxYWWOAYFXaAF/PDia8DLdzatcXiObN2jeaa2gr1vuxFm0M3RKcr6Zh8OevU6qyHG ZQiXBgfnyejV/eiN/sq+nu9d4zwkQOo0ZoXgQkJ5AKCnlxitKAsf4FT7gV/cyfL0j6iw FuXSsUVgQLvOsDXcIXD36vQ4ZFAmO9KwoJqFfrGQp4f9EMlIJCurXjk90JHewSqbdqtO HSAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=FteSFK9+97P2dFFwwOOZ3FBdYgQVfdGi6UPMpkEohYE=; b=5wumJzEbUd/ikKl0yaNizU9aR6hRQA0RmAEsGMOHKn/2ybEdE4EXIM1aethX+O8kYZ rdZoONpcHRuryB067nOSbU5NNlyyzyOOKucgB9wPULZy8XxOaBLzzFAeUxm2idBQjulW b0JEwLiBSt8lHwbgQqG+/+Kb/ab5puAcNHEDTHs7wE1aEit8nLyZRs0I6BM9Uuo02+j5 WyqkqeweM13Fr56SRcgsFZW4k08uUOcrIhIPs6D+ElUT+CZKZTkPcUIBRpJK9FmYTUZY 9DMdjLWU9x5Ufo0BDx4fdG9AXY/2XAQBe/b7j6ad79Lk9BmEtu+lWbNEkj5UhecAXoQX KycQ== X-Gm-Message-State: AOAM5322UqxTvTHMzU2ZXeamTV60ikHpPt9kNZAR1YhdOYR19A03O+eu eTO+5JaXVT6cY5xi7HXMsvRfp51iTY8= X-Google-Smtp-Source: ABdhPJwUmdSYaEeWGK2Gc5Di4814XrhjP7ajf0vVeoKsLiENbjCybatiiAqn7z9olrN8mi+1M7xuIQ== X-Received: by 2002:a05:600c:1553:: with SMTP id f19mr9002289wmg.66.1632298498328; Wed, 22 Sep 2021 01:14:58 -0700 (PDT) Original-Received: from ars3 ([2a02:8109:8ac0:56d0::2f72]) by smtp.gmail.com with ESMTPSA id j21sm1244440wmj.40.2021.09.22.01.14.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Sep 2021 01:14:57 -0700 (PDT) In-Reply-To: <878rzpw7jo.fsf@gnus.org> (Lars Ingebrigtsen's message of "Wed, 22 Sep 2021 06:36:27 +0200") Received-SPF: pass client-ip=2a00:1450:4864:20::429; envelope-from=arstoffel@gmail.com; helo=mail-wr1-x429.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:275304 Archived-At: On Wed, 22 Sep 2021 at 06:36, Lars Ingebrigtsen wrote: > We introduced `thread-last' in 2014, and there seems to be one (1) place > in the Emacs code base, so I guess that didn't take off, but rewriting > with that, we get: > > (org-babel-read > (concat "'" > (thread-last > results > (replace-regexp-in-string "'" "\"") > (replace-regexp-in-string ",[[:space:]]" " ") > (replace-regexp-in-string "\\]" ")") > (replace-regexp-in-string "\\[" "(")))) > > Which is somewhat more readable (but note that this totally breaks down > if you want to mix in LITERAL etc). Clojure has a moderately useful named variant of the threading macro for this kind of situation: (as-> expr name & forms) Binds name to expr, evaluates the first form in the lexical context of that binding, then binds name to that result, repeating for each successive form, returning the result of the last form. (I guess I would have chosen the opposite order of the 'expr' and 'name' arguments, though.)