From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Adam Porter Newsgroups: gmane.emacs.devel Subject: Proposing "alist" macro Date: Fri, 17 Aug 2018 20:57:07 -0500 Message-ID: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: blaine.gmane.org 1534557376 22862 195.159.176.226 (18 Aug 2018 01:56:16 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 18 Aug 2018 01:56:16 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Aug 18 03:56:12 2018 Return-path: Envelope-to: ged-emacs-devel@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 1fqqTL-0005oT-Lh for ged-emacs-devel@m.gmane.org; Sat, 18 Aug 2018 03:56:11 +0200 Original-Received: from localhost ([::1]:37262 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqqVS-000368-3x for ged-emacs-devel@m.gmane.org; Fri, 17 Aug 2018 21:58:22 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49124) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fqqUV-00035C-95 for emacs-devel@gnu.org; Fri, 17 Aug 2018 21:57:23 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fqqUS-0002BP-5W for emacs-devel@gnu.org; Fri, 17 Aug 2018 21:57:23 -0400 Original-Received: from mail-ed1-f53.google.com ([209.85.208.53]:35786) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fqqUR-0002Ad-Vi for emacs-devel@gnu.org; Fri, 17 Aug 2018 21:57:20 -0400 Original-Received: by mail-ed1-f53.google.com with SMTP id e6-v6so5462219edr.2 for ; Fri, 17 Aug 2018 18:57:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=+q8gWwMwKVTtqlVs2CN5OpWjryyhMgxYNPspDOYGL3E=; b=lEzpVYLyGBQG5cWzQp0Olf8ioTZ6o3f5CpoOFsW/3rxMMzrAqywn2xVhHwyYL/Wbwi b4bCq9j47dVm12Fl/3vPa7cjiIAX0H73xD17+ygah8Roy3OSnulujqtFJH085IXSZIhs TA2kcGYaGMVLMN2SFP4R3X5w24gzsuMoPryGw9E5PP8/W+NNlRYYvPi6Ir1AHnjSO3rR WQ7dQhW/4rbvTwqZnXADrltsII0f91jDPru/gmZLVCQXIOuVV4vp8cZ9lS/PX2/YtctY hiPoEPAN+VGPKMaOH31nsyHVe8ogdPVGjYwkY0gSdb2QEGk6ixzU9D602nwpokMmwCne uQ9w== X-Gm-Message-State: AOUpUlGNhzUnuuAStqAG/hUltovR4SjOvTpNko4VHDnPpgZu+cYvnUZz 5oQEHYhnm11VK/JrXoJMvoHMRqseLeirc7yFAzKAnJ8q X-Google-Smtp-Source: AA+uWPwss5AEIUPcfaBQggZOSCzJ5XThCkDEwWfDepTbOlx8Xd4xrWW9bGNL7hyurvXLnJ4s65ftrKtjvr1e+2i/Kgk= X-Received: by 2002:a50:91da:: with SMTP id h26-v6mr43840947eda.87.1534557438675; Fri, 17 Aug 2018 18:57:18 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.208.53 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 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.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:228650 Archived-At: Hi, I've found the a-list function from the a.el library to be very helpful for building alists, e.g. instead of: #+BEGIN_SRC elisp (let ((a 1) (b 2)) (list (cons 'one a) (cons 'two b) (cons 'three 3))) #+END_SRC Or: #+BEGIN_SRC elisp (let ((a 1) (b 2)) `((one . ,a) (two . ,b) (three . 3))) #+END_SRC I can write: #+BEGIN_SRC elisp (let ((a 1) (b 2)) (a-list 'one a 'two b 'three 3)) #+END_SRC However, a-list runs mapcar and seq-partition at runtime. Also, few people have a.el installed, and people seem reluctant to install it. So I'd like to propose this macro for addition to Emacs: #+BEGIN_SRC elisp (defmacro alist (&rest args) "Build an association list from the keys and values in ARGS. ARGS is a list of alternating keys and value forms, like a plist. For example: (alist 'one 1 \"TWO\" \"2\" 3 (nth 3 var)) Expands to: (list (cons 'one 1) (cons \"TWO\" \"2\") (cons 3 (nth 3 var)))" `(list ,@(cl-loop for (key value) on args by #'cddr collect `(cons ,key ,value)))) #+END_SRC If this is acceptable, I'd be happy to provide a patch with whatever changes are desired. Thanks.