From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:403:4789::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms9.migadu.com with LMTPS id QKTmEZKpwWQACAAASxT56A (envelope-from ) for ; Thu, 27 Jul 2023 01:17:38 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:4789::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id QFD0EZKpwWRhUgEAauVa8A (envelope-from ) for ; Thu, 27 Jul 2023 01:17:38 +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 CB9D253F5E for ; Thu, 27 Jul 2023 01:17:37 +0200 (CEST) Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=runbox.com header.s=selector1 header.b="Nq nu/hY"; 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"; dmarc=pass (policy=quarantine) header.from=runbox.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1690413458; 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=kFzmLx2Qqo5QXUHulRdUyCmIBvWjWfzrxTZugKgubBE=; b=WANV0/9OqkVr14pANzXG8/5t4BSwH9/Vl87tqw6T4uzkKaaLVIbXj8WtmYSktdY4ONyyzP 6mPLXHqvNxmuB6EZXRO3jikFggxlofnIWwO+dq0i8s5dz2M/esyyWm2HYJZG4XecI1jRCu 3n/p5/u0j+gLZFOlV281KzUymW6Cwpij34knTZDF2q7onfTTiXgJYy4bCKEgLLQ9GW967F tC9YYUeIXvwChaQJAkNVYrIVQCkoKXxj/AXNzoSvqdDM2PMSE8j0+rBc483uC/t9If0Tw7 Psq+8+/37f4EeYE7oxe2bFi/C/Hili5IFU5O+6YWy7pz79ppjGJaqS+gXKt14A== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1690413458; a=rsa-sha256; cv=none; b=uxaHhyKGEVpEfaKWWI7zZ6H57JM54cijK8B1ylyTXS0PR6Ncwe6azt3rsIhvkiDqFNL+Oe zgkJ7Spak/BhIH/wXFuQ1HjLSYsQbe8GMxxWeEs4h0/0k0Uha/v4tnbURBEMoKbJGYciXp D3v50lKtcWBSuhRIamETiGK6St384wQjuX4gXT57FLTA0rNmwzFWeQoX1hi6ashjdfn2ml dnL06y22ki6I2x5XlG2Hom6sYnlF7geBoS+xftHr4Z81JEK82OWh/98vKhrWHLKQMrrTCq uSdgJJ3ujobpU1fLuk0jtaq3Uz0EoTN6qp/OR02ll5Bnb31RUgxE0dpnlEYwqw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=runbox.com header.s=selector1 header.b="Nq nu/hY"; 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"; dmarc=pass (policy=quarantine) header.from=runbox.com Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qOnfs-00026P-Cg; Wed, 26 Jul 2023 19:12:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qOnfo-000260-QU for emacs-orgmode@gnu.org; Wed, 26 Jul 2023 19:12:06 -0400 Received: from mailtransmit04.runbox.com ([2a0c:5a00:149::25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qOnfm-000091-I8 for emacs-orgmode@gnu.org; Wed, 26 Jul 2023 19:12:04 -0400 Received: from mailtransmit02.runbox ([10.9.9.162] helo=aibo.runbox.com) by mailtransmit04.runbox.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1qOnfe-001ytb-5l; Thu, 27 Jul 2023 01:11:54 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=runbox.com; s=selector1; h=Content-Type:MIME-Version:Message-ID:In-reply-to:Date:Subject :Cc:To:From:References; bh=kFzmLx2Qqo5QXUHulRdUyCmIBvWjWfzrxTZugKgubBE=; b=Nq nu/hYhYbKbHMtEYYxSTKEKpwVsMGL90OBApZMX4a90VgymZw9yKRCd4EFski8ERc/+aot9rpUXbop uKN2SQp4GVXNfA7fR6Yeumb+w6ZHcyHlBojbG9yOx9eLc0O/YIZ0RNEuh/8IbbW22QS2SVRVQwMWu sk4Lws0FTseB2sN/FahZ+AMMOnePnay6h2a2aq6Bp4nG8iZ1DAVI1I+Gn6gshUM/1gY+XgK8V7JPK HXq9wQ023m+vuRyw/0wFo1DMKbJT9OvdIeELtJ+xnLtJ2sYHwI8sm6tW5pGH0UiWKDCex88+/2sAa B2wq7SbEkuDP84jKyRcfxix1l3rnSA+A==; Received: from [10.9.9.73] (helo=submission02.runbox) by mailtransmit02.runbox with esmtp (Exim 4.86_2) (envelope-from ) id 1qOnfd-0002dg-6y; Thu, 27 Jul 2023 01:11:53 +0200 Received: by submission02.runbox with esmtpsa [Authenticated ID (946465)] (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) id 1qOnfL-0002cG-P4; Thu, 27 Jul 2023 01:11:36 +0200 References: <877cqwbpa2.fsf@runbox.com> <4fee1ca5-4d38-0bb9-1931-ee554307ac4d@gmail.com> <87wmyoks82.fsf@runbox.com> <8b17c390-4aa7-f988-aa9c-54479b8b4461@gmail.com> User-agent: mu4e 1.10.4; emacs 29.0.92 From: Gavin Downard To: Max Nikulin Cc: emacs-orgmode@gnu.org Subject: Re: [PATCH] lisp/org-table.el: Allow named columns on lhs Date: Wed, 26 Jul 2023 14:50:21 -0700 In-reply-to: <8b17c390-4aa7-f988-aa9c-54479b8b4461@gmail.com> Message-ID: <87pm4exobn.fsf@runbox.com> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=2a0c:5a00:149::25; envelope-from=gavin.downard@runbox.com; helo=mailtransmit04.runbox.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, 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-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -9.29 X-Spam-Score: -9.29 X-Migadu-Queue-Id: CB9D253F5E X-Migadu-Scanner: mx1.migadu.com X-TUID: GZBUgofC8DKV Max Nikulin writes: > The regexp for parsing formulas does not allow named references after @. > I have no idea if other code should be modified as well. I consider it > as more important than detection of duplicated definitions. Yeah, besides changing the regexp, the main thing that will need to be changed is the interface of `org-table-get-stored-formulas'. Currently, a field name on the lhs can only exist by itself (that is, it can't be a part of any other expression, such as a range), so the leading '$' is removed. So, '$name=1+2' is parsed as '("name" . "1+2")'. This is at odds with field/column names in the middle of an expression. I think the best way to do this is to change `org-table-get-stored-formulas' to not strip the leading '$', and instead of using '(assoc FIELD-NAME org-table-named-field-locations)' or '(assoc COL-NAME org-table-column-names)', we can a modified* version of `org-table-formula-substitute-names' (which is used for field and column names on the rhs of a formula). That would work as a replacement for the existent handling of field names that would also work for column names as we want them. As a side note, this would allow ranges on the lhs that contain field names in them: | | 1 | 2 | 3 | | # | | | | | ^ | begin | | end | #+TBLFM: $begin..$end=@1*@1 (*): the issue with `org-table-formula-substitute-names' as it is, is that it will replace field names with the field /value/, not the field index. Hopefully modifying the function to replace field names with their indices won't break anything, so we can use the same function for both sides of the formula. > A crazy idea: several columns may have the same name: > > | | Jun sum | Jun count | Jun avg | Jul sum | Jul count | Jul avg | > | ! | | | average | | | average | > |---+---------+-----------+---------+---------+-----------+---------| > | | 150 | 10 | | 200 | 14 | | > > #+tblfm: $average=$-2/$-1 > > It has no sense for numeric references but with names it can help to > avoid repeated expressions. Or, if you want to get really crazy, we can let fields and columns with the same name share a formula. :) | ! | Apple budget | Pear Budget | Orange Budget | total | |---+--------------+--------------+---------------+---------------| | # | 1 | 2 | 3 | 6 | | # | 4 | 5 | 6 | 15 | |---+--------------+--------------+---------------+---------------| | # | 2 | 3 | 5 | 26 | | ^ | extra-cost-1 | extra-cost-2 | total | ultimatetotal | #+TBLFM: $total=vsum($<<..$-1) :: $ultimatetotal=vsum(@I..II) + $-1 But in all seriousness, that does seem like it could be useful. I guess on the rhs we could give each of those "shared names" the value of an array of that name's connected columns (or fields). But I think support for that should probably be added in a separate patch, since it's a bit separate from the main issue.