On Mon, Jun 17, 2019 at 11:08 PM Uwe Brauer <o...@mat.ucm.es> wrote:

> >>> "MB" == Michael Brand <michael.ch.br...@gmail.com> writes:
>
> > Hi Uwe
> > On Tue, Jun 11, 2019 at 11:36 AM Uwe Brauer <o...@mat.ucm.es> wrote:
>
> >> Is this behavior possible? When I delete a row or a column, the  TBLFM
> >> is updated, could that be done for reordering?
>
> > You may want to use something like this, (I knew the syntax for ~"$1"~
> > and used the formula debugger ~C-c {~ to find the syntax for
> > ~"(Smith)"~):
>
> > | name   | C1 | C2 | Res |
> > |--------+----+----+-----|
> > | Smith  |  9 |  1 | 1.7 |
> > | Miller |  6 |  2 |   8 |
> > | Adams  |  5 |  5 |  10 |
>
> > #+TBLFM: $4 = if("$1" == "(Smith)", 0.1 * $2 + 0.8 * $3, $3 + $2)
>
> Ha, of course, thanks, why did that occur to me? I am bit surprised by
> the () in Smith, should "Smith" not be sufficient? But it is not indeed,
> how odd?
>

Indeed, this looks very weird.  It has to do with the fact that table
formulas usually deal with numbers and expressions and not with strings.
When replacing $1 in a calc formula, Org adds parenthesis to allow also
algebraic expressions in such formulas.  Consider the following case:

| 2 | 2+3 | 10 |
#+TBLFM: $3=$1*$2

This formula needs to be interpreted as 2 * (2+3).  Without the
parenthesis, it would be read as 2*2+3, which is 7, not 10.
Basically, we need to make sure that whatever is in the field is
interpreted as one entity and not ripped apart by the operator precedence
in calc.  And therefore, indeed, if you want to compare strings, you need
to add the odd-looking parenthesis inside the double quotes.

I guess we should document this.  For lisp formulas, I did document the
variable interpolation, but apparently not for calc syntax.
I will put this into the manual.

Carsten


>
> Anyhow, thanks a lot.
>
> Uwe
>

Reply via email to