emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@posteo.net>
To: Jeff Trull <edaskel@att.net>
Cc: emacs-orgmode@gnu.org
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	[thread overview]
Message-ID: <87leiiub1o.fsf@localhost> (raw)
In-Reply-To: <CAF_DUeG_W_40Ws_8Z+0Q=f_2yzT+cE9aoUxDbLnnb1n7-HDbaQ@mail.gmail.com>

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	other threads:[~2023-04-23 10:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAF_DUeG_W_40Ws_8Z+0Q=f_2yzT+cE9aoUxDbLnnb1n7-HDbaQ.ref@mail.gmail.com>
2023-04-22 14:20 ` [BUG] text cell contents have extra parentheses when used in formulas [9.6.4 ( @ /home/jet/.config/emacs/elpa/org-9.6.4/)] Jeff Trull
2023-04-23 10:50   ` Ihor Radchenko [this message]
2023-04-23 19:57     ` Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87leiiub1o.fsf@localhost \
    --to=yantar92@posteo.net \
    --cc=edaskel@att.net \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).