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 ms0.migadu.com with LMTPS id 2NASEt2NFmLQRwEAgWs5BA (envelope-from ) for ; Wed, 23 Feb 2022 20:41:17 +0100 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 8JlrD92NFmJqWQEA9RJhRA (envelope-from ) for ; Wed, 23 Feb 2022 20:41:17 +0100 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 D7E48291E0 for ; Wed, 23 Feb 2022 20:41:16 +0100 (CET) Received: from localhost ([::1]:33688 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nMxVj-0000h1-Aj for larch@yhetil.org; Wed, 23 Feb 2022 14:41:15 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52314) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nMxUP-0000gn-Qy for emacs-orgmode@gnu.org; Wed, 23 Feb 2022 14:39:53 -0500 Received: from [2607:f8b0:4864:20::f34] (port=40795 helo=mail-qv1-xf34.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nMxUO-0007Vr-3Y for emacs-orgmode@gnu.org; Wed, 23 Feb 2022 14:39:53 -0500 Received: by mail-qv1-xf34.google.com with SMTP id fc19so10220993qvb.7 for ; Wed, 23 Feb 2022 11:39:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=2k1GvEhvHwxEMljfkkTIQYL894RT5a3Vfn4WRar+YcI=; b=fUcUjBY4QjZIUwnTQfXEfuBtN9KHD8U6Z7NbEVvNUtsG8aF9TeFI5SrOLl5mmZM1lW ewWFTmS4FK6bsDz8DW7iiiLSEdiEtBHxb0gz0zrSJlXfIyEGxiaTSIEQzxweMcXqlWiu 9fKmu5+oDFBR4692pvjS1uL3F59QPKfVRNz01Ez2wc5CfzCBXVDt9ATtfR2CxzrJFvkj MhT77JOZGhVI+2lZN/eEZ01jRNlwRjSewa+yQ/YJ5j9ZLg9f+TsEHja9720fohYTf6/m 1hAB8Mu8/wOD1qpy1M1FuQOUYrSjgCH6KIfStncwMdBcP0iYPiZE7Jhgw14aB+QXKD8S 1D9w== 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:date:message-id:mime-version :content-transfer-encoding; bh=2k1GvEhvHwxEMljfkkTIQYL894RT5a3Vfn4WRar+YcI=; b=Z9cdYZ6w79t8u4xEcc3fjvUS36jKVIW3eR82Zy6KJRbbE0IU7pSlA6gK525/xazbml QfCDlbZre/1G/6EzZ7T35vQ5DcX6nRiK5M7jbw79d4HNee0KtviKklG585KnmJhPlQHK O+tWmPlb7rOXEZRU04yg1gq7dKtEfAL7336CwQZbIjltPEZIyqdEdXGzRmA+TGd82Nx7 STwx3dP8BZ0DUhM6cdmOrSjLKMAK8/BOK3EBSmdQq/Qkw/8/X+C3KHwqzvJIIWZjz5b0 IFHPULMvz2coKMAR65X5+b7O/PqwEWS2p1oIkueHkzQDezAArpUuRaDRU0FH4YetimDe RVCg== X-Gm-Message-State: AOAM533Gg4XuOw5Rt6pWgFkkdcZKdvOzCuBYMhg0KkE/mdDBBUghIGGJ 3KjcfzZ09g2ybRo1i1KRucif7vGmpvo= X-Google-Smtp-Source: ABdhPJyHhByweyVP3n4uGft2pIHv9T+sgY535YZ1TXue51xDMz0cLk2twx9cMfZsBjVugESilJEAvA== X-Received: by 2002:a05:622a:1787:b0:2cf:9441:19e8 with SMTP id s7-20020a05622a178700b002cf944119e8mr1238070qtk.499.1645645190946; Wed, 23 Feb 2022 11:39:50 -0800 (PST) Received: from nazrul.hsd1.fl.comcast.net ([2601:58b:1000:750::9895]) by smtp.gmail.com with ESMTPSA id l1sm323699qtp.4.2022.02.23.11.39.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Feb 2022 11:39:50 -0800 (PST) From: necaris@gmail.com To: emacs-orgmode@gnu.org Subject: [PATCH] Send table rows to OCaml as tuples Date: Wed, 23 Feb 2022 14:39:34 -0500 Message-Id: <20220223193934.226994-1-necaris@gmail.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::f34 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::f34; envelope-from=necaris@gmail.com; helo=mail-qv1-xf34.google.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 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, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no 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: , Cc: Rami Chowdhury Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1645645276; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=2k1GvEhvHwxEMljfkkTIQYL894RT5a3Vfn4WRar+YcI=; b=HZGPu4X+wgfymJbWLDL5Oyi0I0MGrNAT4tPSKCyzcw+CGfOPeRVcaKwiTm7prD+YI8fu/d DTegpECCP+eujvhRrOhH4rrXd28A7Z7QIxv6steHyznY43A0Id/W4+qGV8X+SIL20jDCCY jNizLgG7On65hDNGfPaH18LwEa42+t2odfjI5N+SiC9XxBGziIW6c48DwdcPn7N6owJd+T +8i20DYea0mSIy9EF3igXh7UQp/e6UdDBI3uIoWGY1I4JrfSUbfxBDo2zdFXEhe3iEDZJZ ngW+dQGFVuQoylWFHRkMvBVjhuWOAuuD7k86Y23WWjhwqkYT+sdPqvnYpM4J6g== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1645645276; a=rsa-sha256; cv=none; b=N4r/v8mqPfjjaZHeWxEOkVLyLB/WfphLXTj/HC8i2ZXahNoqu+eCSCaHiWHhsLnZEOMv5H ZaTmktcd5vr2s78WdSvWZmcYxevyEJFI/4YP+WahfQvo+5vT9LYJHjUpieyDICtmIlUk7/ AZEU6kPr0f8lJN2nH1Rc7UFWVfB3Z6u8EDtJLArZutYtrQdGcxJ+wy6ukFAE2tGibW5a1y QtlL1QuEJUinIVMgy+sJk6PzWtqSpwR4ibzufxl/FDR6FEpP0/IbR4vnE+GJXROrOFO+Uu L4G4BklVHGgBqPHQBxUYswoJYciRsWdPbLb641nDQ9zo74ArTbXYxa3gQ/+9Qw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=fUcUjBY4; 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: -2.83 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=fUcUjBY4; 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: D7E48291E0 X-Spam-Score: -2.83 X-Migadu-Scanner: scn0.migadu.com X-TUID: viEQm307LIPJ From: Rami Chowdhury Previously, tables (i.e. lists-of-lists) came through as arrays-of-arrays. Since OCaml arrays are required to be homogeneous in their types, this meant tables with heterogenous types within a row could not be handled. This change represents tables as arrays of tuples, which is more flexible, while preserving the previous behavior for lists. * lisp/ob-ocaml.el (org-babel-ocaml-elisp-to-ocaml-tuple, org-babel-ocaml-elisp-to-ocaml-array, org-babel-elisp-to-ocaml): Send table rows as tuples --- lisp/ob-ocaml.el | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lisp/ob-ocaml.el b/lisp/ob-ocaml.el index 80df795..ad7df97 100644 --- a/lisp/ob-ocaml.el +++ b/lisp/ob-ocaml.el @@ -123,11 +123,23 @@ (org-babel-ocaml-elisp-to-ocaml (cdr pair)))) (org-babel--get-vars params))) +(defun org-babel-ocaml-elisp-to-ocaml-tuple (val &optional nested-renderer-f) + "Return OCaml evaluating to VAL, with elements rendered by NESTED-RENDERER-F." + (let ((renderer (or nested-renderer-f #'org-babel-ocaml-elisp-to-ocaml))) + (concat "(" (mapconcat renderer val ", ") ")"))) + +(defun org-babel-ocaml-elisp-to-ocaml-array (val &optional nested-renderer-f) + "Return OCaml evaluating to VAL, with elements rendered by NESTED-RENDERER-F." + (let ((renderer (or nested-renderer-f #'org-babel-ocaml-elisp-to-ocaml))) + (concat "[|" (mapconcat renderer val "; ") "|]"))) + (defun org-babel-ocaml-elisp-to-ocaml (val) "Return a string of ocaml code which evaluates to VAL." - (if (listp val) - (concat "[|" (mapconcat #'org-babel-ocaml-elisp-to-ocaml val "; ") "|]") - (format "%S" val))) + (cond ((and (listp val) (listp (car val))) + (org-babel-ocaml-elisp-to-ocaml-array val #'org-babel-ocaml-elisp-to-ocaml-tuple)) + ((listp val) + (org-babel-ocaml-elisp-to-ocaml-array val)) + (t (format "%S" val)))) (defun org-babel-ocaml-parse-output (value type) "Parse VALUE of type TYPE. -- 2.35.1