emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [BUG] text cell contents have extra parentheses when used in formula


From: Ihor Radchenko
Subject: Re: [BUG] text cell contents have extra parentheses when used in formulas [9.6.4 ( @ /home/jet/.config/emacs/elpa/org-9.6.4/)]
Date: Sun, 23 Apr 2023 10:50:59 +0000

Jeff Trull <edaskel@att.net> writes:

> Expectation: when using cell contents as strings in a formula, the
> strings should contain exactly the cell's text contents
>
> Actual: the resulting string is wrapped in parentheses

This is actually expected, although surprising.

> I can find nothing in the documentation that suggests this is expected,
> and it is quite unintuitive if you want to (for example) filter on
> a column.

In short, do not use ".
For filtering, see 3.5.7 Lookup functions.

> #+TITLE: text formula repro
>
> | Key | Value        |
> |-----+--------------|
> | A   | [40, 65, 41] |
> | B   | [40, 66, 41] |
> #+TBLFM: $2="$1"
>
> Here you can see that the contents of the Key column were wrapped in
> parentheses (ASCII 40 and 41) when turned into strings.

If you turn formula debugger on (M-x org-table-toggle-formula-debugger),
you will see the following (I also added extra explanations):

Substitution history of formula
Orig:   "$1" ;; begin calculation of $1 field value
$xyz->  "$1" ;; after handling relative references
@r$c->  "$1" ;; after handling cell references
$1->    "(A)" ;; after handling column references; the (...) is added
              ;; because of Calc syntax to ensure that values inside
              ;; cell are grouped. There is no notion of strings in GNU
              ;; Calc (AFAIK). So, (...) grouping always represents
              ;; algebraic Calc expression.
Result: [40, 65, 41] ;; (calc-eval "\"(A)\"")
Format: NONE
Final:  [40, 65, 41]

As you can see, we passed the formula to GNU Calc.
However, "foo" in GNU calc is nothing but a vector of characters.
So, $2="$1" is not what you anticipated.

You may refer to 3.5.2 Formula syntax for Calc where we put a reference
to GNU Calc manual. It is out of scope of Org manual to describe how GNU
Calc works.

Do note that an alternative formula syntax is using Elisp (see 3.5.3
Emacs Lisp forms as formulas). You can use that syntax if you prefer it
over GNU Calc.

Canceled.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]