From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id WELoNoJK6mJLXwAAbAwnHQ (envelope-from ) for ; Wed, 03 Aug 2022 12:14:26 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id QGP4NoJK6mKwjAAA9RJhRA (envelope-from ) for ; Wed, 03 Aug 2022 12:14:26 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 9EEDF1FD16 for ; Wed, 3 Aug 2022 12:14:26 +0200 (CEST) Received: from localhost ([::1]:42344 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJBOT-0004oH-DE for larch@yhetil.org; Wed, 03 Aug 2022 06:14:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35732) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJBMn-0004j9-Df for emacs-orgmode@gnu.org; Wed, 03 Aug 2022 06:12:41 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]:38415) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oJBMl-0006Sh-Bp for emacs-orgmode@gnu.org; Wed, 03 Aug 2022 06:12:41 -0400 Received: by mail-pl1-x630.google.com with SMTP id o3so15968425ple.5 for ; Wed, 03 Aug 2022 03:12:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=600VY5PclCKPFwEXZfHq7XupcEAh5gg4OYL+6wUYMbg=; b=DdUrboD6Jw5ehvuQru7Kgg7P9ZVDMcovxMKERcyxo5yKXSKy5hjf2XX5EXteFgVELR ZMGauUk8o5ELgCe+BdIPAVfaGfsuV4RFfZHsYog7BbFh4bczxADdH6k1HSM1MaMUyzyr xnAVkpyj1XeIKwlLbpn6Mz/0GVERuULZ/DeSQjUL2mlo6VeZpK+QzgXd3gVbVjfaNuB1 k3NDPPLHag2CYreEiQ5vLLrZz6yOne272JLdyf2bLq8SN1Oim+HXFGeSMzD84EDkhkeE WdmuNauB+BzJSdKz5VO2GQdkTGjncd6etDhH0Ebm9spAcCy8gv6wpsnS7MnYv7hU5JgF 22JQ== 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:in-reply-to:references:date :message-id:mime-version; bh=600VY5PclCKPFwEXZfHq7XupcEAh5gg4OYL+6wUYMbg=; b=dFwAcj2wrLWc9+42JkVx3uXBkKG00VZIS97qZqR2xRNij9fhtLn97qxSXsyktbyBzs E+ZSXgFenhw4V5NHzi+zkZrBbY3ZHwevse077NS7XINJKd3A2ilzTlJcs2UNkVUvLP6i xPzZ7zFyHaG4H36LeQdohcw0RL1IzJ8J25Xj5nRit5AyUu+3wWnF6VxilYHatQV+iGrj HnZOk6j/vSR8mVjsXwxIowVtOoe24XwPT3t3EBs9I0quXUYeyW77lwTg6Mz1I2D30D8P EkqpbFEc34Ga4I7TJ51c18aYDgTlJ4llWeAPzLC7OH55wcw4I14IqCRzzMttFMJDsrNb /Zag== X-Gm-Message-State: ACgBeo2DlAA+NIPV9bfRjcDK3CaOIq5m5uMBUX+uJ0ngYx50iVKvoRlk wWdgAlxaWxle7RDpGvIAusP2tiLKDs86GQ== X-Google-Smtp-Source: AA6agR4cXUhzJ5Us2rnJgX3r2/2HrCVHX7I19VQ6QXbcqYrPN7yEouaZyRwGzrPOXL5VpNpcRqaRLA== X-Received: by 2002:a17:90b:38c8:b0:1f5:1311:5bd3 with SMTP id nn8-20020a17090b38c800b001f513115bd3mr4117672pjb.161.1659521556890; Wed, 03 Aug 2022 03:12:36 -0700 (PDT) Received: from localhost ([115.154.175.57]) by smtp.gmail.com with ESMTPSA id 68-20020a621647000000b0052d432b4cc0sm7403216pfw.33.2022.08.03.03.12.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Aug 2022 03:12:36 -0700 (PDT) From: Ihor Radchenko To: Mark Clements Cc: "emacs-orgmode@gnu.org" Subject: Re: Elisp macro for working with org tables In-Reply-To: References: Date: Wed, 03 Aug 2022 18:13:43 +0800 Message-ID: <87r11xiqi0.fsf@localhost> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2607:f8b0:4864:20::630; envelope-from=yantar92@gmail.com; helo=mail-pl1-x630.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1659521666; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=600VY5PclCKPFwEXZfHq7XupcEAh5gg4OYL+6wUYMbg=; b=bBHQj4QgJebYE8lYefaG95Y52A9tuLmOtYplLp/zlJBYfNxj3hiTBuHR1CpnotsMo9s7OL vESXoHOaZGjMiMd0u+copRk6+fH/UrDEL2Dnpoj8A5Q81l+OO2UbIwMRp1TAOsz0Dijg8v 6+tEubi53RTeUUyW6g0aatpb/cx8gnbm7ng/+OOV5FufOUxn3wKK0rUUPX36ADRq+KHLj3 nMkU9Drrk2YGmUk0aL3In+djceQCzYYDpIvXTs+Pkpgt6lzRQhBRy/dX8If7lG5jNCYdMv CAjGO6xfp2oWiCEM8wgAUCAxtbZdkGJBwtdrbisV1c3VKAy3DchzhP48Y64Ogg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1659521666; a=rsa-sha256; cv=none; b=MAjqxNvjFq28pqatS6s4tbhqqTRvrM31lM3I5x18I8t3IY0bt87qjdLTIPLm6B9dDnCGab PvQ3mNLk5tjQZJQhD94ZWwGI3jqoXPfl9kE0TpgLbmRXU0QPvyyfJf9k735Kn8pJ6GObpD gknockRb+MRfTXc7NRXx++lbvFFx+BPLrCX6xERjTXQkLHFW2If6a3V242CaZNzv8E80Cl OSyy9S4G14u0y69WXVz8wMtUqb2ajIaLh/cTx21k94Zg9fuJQnGW+gPEwPPEks/KWIM/Us xIKj+taZIYHS5bhWflNrzSQvhk/757QICW7mKHV31kDnf+2SwtY35eNmYavZ2Q== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=DdUrboD6; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -6.91 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=DdUrboD6; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 9EEDF1FD16 X-Spam-Score: -6.91 X-Migadu-Scanner: scn0.migadu.com X-TUID: TCOdEbE3m7PW Mark Clements writes: > In response to a question on Stackoverflow (https://stackoverflow.com/questions/50921305/org-table-and-named-columns-for-babel-processing), I have written an elisp macro to work with org tables: > > #+NAME: test-table > | a | b | > |---+---| > | 1 | 2 | > | 3 | 4 | > .... > Comments are welcome -- and I hope that this is useful. Usually, we use table formulas in such situations. Table formulas support named columns, lines, cells and constants. > #+NAME: test-table-script > #+BEGIN_SRC emacs-lisp :var table=test-table :colnames no > (require 'cl) > (defmacro with-table (table expression) > "Given an org table with colnames, evaluate an expression using the colnames. > Note: use ':colnames no' in the header -- this imports the names but does not export them." > `(let* ((table-with-colnames (org-babel-get-colnames ,table)) > (names (loop for name in (cdr table-with-colnames) > collect (if (stringp name) (intern name) name)))) > (funcall > `(lambda (data) > (mapcar (lambda (row) > (cl-destructuring-bind ,names row ,',expression)) > data)) Note that NAMES may contain forbidden chars for Elisp symbols. Best, Ihor