From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Artur Malabarba Newsgroups: gmane.emacs.devel Subject: New assoc-let package Date: Wed, 3 Dec 2014 23:40:14 +0000 Message-ID: Reply-To: bruce.connor.am@gmail.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1417650050 20681 80.91.229.3 (3 Dec 2014 23:40:50 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 3 Dec 2014 23:40:50 +0000 (UTC) To: emacs-devel Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Dec 04 00:40:44 2014 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XwJXH-0000Dh-Lg for ged-emacs-devel@m.gmane.org; Thu, 04 Dec 2014 00:40:43 +0100 Original-Received: from localhost ([::1]:43889 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XwJXH-0007K9-B8 for ged-emacs-devel@m.gmane.org; Wed, 03 Dec 2014 18:40:43 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60593) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XwJWq-0007Jt-NA for emacs-devel@gnu.org; Wed, 03 Dec 2014 18:40:17 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XwJWp-00049y-Rk for emacs-devel@gnu.org; Wed, 03 Dec 2014 18:40:16 -0500 Original-Received: from mail-lb0-x22a.google.com ([2a00:1450:4010:c04::22a]:52884) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XwJWp-00048A-JR for emacs-devel@gnu.org; Wed, 03 Dec 2014 18:40:15 -0500 Original-Received: by mail-lb0-f170.google.com with SMTP id w7so13254196lbi.29 for ; Wed, 03 Dec 2014 15:40:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:reply-to:sender:date:message-id:subject:from:to :content-type; bh=Vg4DUBu35ObtcWQ9EDvWUZEvh3cCzxW8cfhh7hU8QDE=; b=tw2H2A0X+uADsd/jErftLHQbsnu6G0AkOrhNTaQL9bVAqxksXfyumBjTguN8KnNx+s dTmzO2ZzV29NrIRbbcVEFe2rczks0nGB9aUIPQCQmHO+fk0nDd8sWqhdEb2iDfrkgiVI YqkRpWMparOxsPek70eHwPv2/dQm71gwtw20Ui0WqLCUsgW/f6/XJ47uHj+QIaZikOaH OCzZ6Rw9sUVUtX1fWv9ZhiC3PhwA3u0nbfxVACUbb1Spn6AUPEZholMWF0lqrJ+u8Sev Sac5pYGmUfCIrAPY/3GRxt4Fv8wetVTPAj4lfrXsWnWkt72E83+hyrwWk74Fz/GefhoJ Q31g== X-Received: by 10.152.21.9 with SMTP id r9mr6662078lae.76.1417650014505; Wed, 03 Dec 2014 15:40:14 -0800 (PST) Original-Received: by 10.112.53.137 with HTTP; Wed, 3 Dec 2014 15:40:14 -0800 (PST) X-Google-Sender-Auth: T2D2tBYBT9rKeZJUHs-xI5FoxOE X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c04::22a X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 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-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:178787 Archived-At: Hi All, As part of another project, which involves excessive handing of alists, I wrote up a little macro which has turned out to be stupendously useful. I'm just checking whether this functionality is already offered somewhere, because if it isn't I'll make an Elpa package for it. Simply put, the macro takes an alist and a body, and makes the data of the alist accessible by just writing the car of the desired cell preceded by a dot. For instance, the following: (assoc-let alist (if (and .title .body) .body .site)) expands to (let ((.title (cdr (assoc 'title alist))) (.body (cdr (assoc 'body alist))) (.site (cdr (assoc 'site alist)))) (if (and .title .body) .body .site)) Obviously, this only works for alist elements whose car are symbols, and it shadows outside variables whose names start with a dot (which I've never ever run into). Still, this has proven invaluable for processing the output of `json-read'. Cheers Malabarba