From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carsten Dominik Subject: Re: table, calc, reorder and protect calculation in one cell Date: Sat, 10 Aug 2019 16:09:35 +0200 Message-ID: References: <87blz4qxbm.fsf@mat.ucm.es> <87lfxzx6om.fsf@mat.ucm.es> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000002dd730058fc3d8b7" Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:36257) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hwS4B-0003ho-1z for emacs-orgmode@gnu.org; Sat, 10 Aug 2019 10:09:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hwS49-0003Yp-RJ for emacs-orgmode@gnu.org; Sat, 10 Aug 2019 10:09:55 -0400 Received: from mail-ed1-f44.google.com ([209.85.208.44]:46718) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hwS49-0003Wg-Jw for emacs-orgmode@gnu.org; Sat, 10 Aug 2019 10:09:53 -0400 Received: by mail-ed1-f44.google.com with SMTP id z51so11350783edz.13 for ; Sat, 10 Aug 2019 07:09:53 -0700 (PDT) In-Reply-To: <87lfxzx6om.fsf@mat.ucm.es> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: org-mode list --0000000000002dd730058fc3d8b7 Content-Type: text/plain; charset="UTF-8" On Mon, Jun 17, 2019 at 11:08 PM Uwe Brauer wrote: > >>> "MB" == Michael Brand writes: > > > Hi Uwe > > On Tue, Jun 11, 2019 at 11:36 AM Uwe Brauer 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 > --0000000000002dd730058fc3d8b7 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Mon, Jun 17, 2019 at 11:08 PM Uwe = Brauer <oub@mat.ucm.es> wrote:<= br>
>>> &qu= ot;MB" =3D=3D Michael Brand <michael.ch.brand@gmail.com> writes:

> Hi Uwe
> On Tue, Jun 11, 2019 at 11:36 AM Uwe Brauer <oub@mat.ucm.es> wrote:

>> Is this behavior possible? When I delete a row or a column, the=C2= =A0 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=C2=A0 =C2=A0| C1 | C2 | Res |
> |--------+----+----+-----|
> | Smith=C2=A0 |=C2=A0 9 |=C2=A0 1 | 1.7 |
> | Miller |=C2=A0 6 |=C2=A0 2 |=C2=A0 =C2=A08 |
> | Adams=C2=A0 |=C2=A0 5 |=C2=A0 5 |=C2=A0 10 |

> #+TBLFM: $4 =3D if("$1" =3D=3D "(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.= =C2=A0 It has to do with the fact that table formulas usually deal with num= bers and expressions and not with strings.=C2=A0 When replacing $1 in a cal= c formula, Org adds parenthesis to allow also algebraic expressions in such= formulas.=C2=A0 Consider the following case:

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

This formu= la needs to be interpreted as 2 * (2+3).=C2=A0 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 n= ot ripped apart by the operator precedence in calc.=C2=A0 And therefore, in= deed, if you want to compare strings, you need to add the odd-looking paren= thesis inside the double quotes.

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

Carsten
=C2=A0

Anyhow, thanks a lot.

Uwe
--0000000000002dd730058fc3d8b7--