From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id gG8GD/AfXV/uUAAA0tVLHw (envelope-from ) for ; Sat, 12 Sep 2020 19:22:24 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id COBZCfAfXV8iYAAAbx9fmQ (envelope-from ) for ; Sat, 12 Sep 2020 19:22:24 +0000 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 7F208940AFA for ; Sat, 12 Sep 2020 19:22:23 +0000 (UTC) Received: from localhost ([::1]:34248 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kHB6K-0001MK-VQ for larch@yhetil.org; Sat, 12 Sep 2020 15:22:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47340) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kHB5w-0001M7-Vf for emacs-orgmode@gnu.org; Sat, 12 Sep 2020 15:21:56 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]:43176) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kHB5v-00076d-9o for emacs-orgmode@gnu.org; Sat, 12 Sep 2020 15:21:56 -0400 Received: by mail-pf1-x42c.google.com with SMTP id f18so9523925pfa.10 for ; Sat, 12 Sep 2020 12:21:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=user-agent:from:to:subject:date:message-id:mime-version; bh=sEC3CkpS7xTGtqcj8NAhyCnnpEfuKL7kug4r3wtWmBk=; b=ogECVmEXYhe+qRwrBEyMtW2GsrBQd0e3qIuvpqFuMwRqdtHyQci51MsMTDAmaonCgL lF69C7XBTtw1nPdGqLxNglMJwG2cPY0GY5aSNp1CxpRbUdG0BE6IsctfmWOJN6PPRV6/ /eimAzbaWC3+beKV1IEgudKu9dEy5uXnwHP5dFdHAj2Wp0DL5mdDdvlY1Z9Xxpj5afOz DMJEFn1/ZaT5pfpcpb4Vq0OfkWnYdSOY+aq1d48OhPJ+EbqobxO5IU4TX72wHdcFAVoc RM3HkyqyzPmFLxt9hBnJ6sjlpMjPwwgZVH/5izOJKJBAfjxhS0FAjuorC3MjDg8nc/Nk BZRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:user-agent:from:to:subject:date:message-id :mime-version; bh=sEC3CkpS7xTGtqcj8NAhyCnnpEfuKL7kug4r3wtWmBk=; b=oUunfh+cZm8H9nz6durY72pKE1dWCLANn43UXOchP/Vnqten/ppqP6OGlr9yZ7SUts 2DsUZShq5KAqncKwWk+XgiKOhgjuCerI82vZvkh61soJBVRXW4RVnSx7GSOO0yqkYsSY BL53sRZ4g4ibAgsSO6TUXCpNYGTZp0xVDQMi6D9yHwvDYZz1VQyYomfCJHV9Ta841Ft4 usxXp1JGNQTarIJvrhM2sZFC8zoSeNv3YgjGXCC2FdriK7PdjOVbSKmlB0v1T3JD/BWe 5T9z999jLjT9fz1Y5/CTUEUf9qgY5Uhd+5l1w7YeI0t2F98TKueRt2OblxpaEy3eau+I X2+g== X-Gm-Message-State: AOAM530uYfYyZQpIYKTM4qi55nodUUZLLxGHA5UMlwyeHOS+DMK0v7zl yNKL31n+fzeXkW+5K0JDqBploOGAEMnnIqvp X-Google-Smtp-Source: ABdhPJxp8sl4wd926mjxgUhuTkRo9u0Ke77fHBmY06mEg2xgMwknK31PmxsAolKVeMrg+FjV8a97hQ== X-Received: by 2002:a63:c948:: with SMTP id y8mr5876166pgg.164.1599938512749; Sat, 12 Sep 2020 12:21:52 -0700 (PDT) Received: from geus3064linuxwsm (97-126-80-198.tukw.qwest.net. [97.126.80.198]) by smtp.gmail.com with ESMTPSA id y203sm5735898pfb.58.2020.09.12.12.21.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Sep 2020 12:21:52 -0700 (PDT) User-agent: mu4e 1.4.3; emacs 26.3 From: Ken Mankoff To: Org-mode Subject: [O] babel bash :var tables - change from associative to index arrays Date: Sat, 12 Sep 2020 12:21:51 -0700 Message-ID: <87d02qls1c.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=mankoff@gmail.com; helo=mail-pf1-x42c.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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-orgmode@gnu.org X-Mailman-Version: 2.1.23 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-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=ogECVmEX; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Spam-Score: -1.71 X-TUID: BiPW+0IaFqxg Hi Org List, I'd like to submit a patch so that all bash babel arrays are indexed. Are there cons to this that I'm not seeing? It might break some existing code that expects associative arrays. Could this be a breaking change that is included in Org 5.0? I'd like to check on the likely acceptance of such a patch before I take the time to code it. Currently Org Babel uses associative arrays for multi-column bash :var inputs, and indexed arrays if single column. Put differently, for 1D tables the array is indexed [0,1,...,n] and for 2D arrays it is indexed using the first column. Example at the bottom of this email. There are some drawbacks to this method: 1) It drops rows if the first column is not unique (I have tables where the first three columns make a unique index from "|year|month|day|value") and 2) associative arrays do not maintain order, so the code cannot rely on the order of the rows (see example below where "foo2,bar2" order is swapped). If all arrays are indexed, these two issues would go away. -k. #+NAME: tbl1D | foo1 | | bar1 | #+NAME: tbl2D | foo2 | 42 | | bar2 | 24 | #+NAME: print_tbl #+BEGIN_SRC bash :var tbl=tbl1D for key in "${!tbl[@]}"; do row=${tbl[$key]} echo $key $row done #+END_SRC #+CALL: print_tbl(tbl=tbl1D) #+RESULTS: | 0 | foo1 | | 1 | bar1 | #+CALL: print_tbl(tbl=tbl2D) #+RESULTS: | bar2 | 24 | | foo2 | 42 |