From mboxrd@z Thu Jan 1 00:00:00 1970 From: Cecil Westerhof Subject: Re: how to clear computed values Date: Wed, 11 Jul 2007 10:26:25 +0200 Message-ID: <1184142385.6253.115.camel@Barebusta.DecebalComp> References: <1184092729.6283.91.camel@Barebusta.DecebalComp> <93de834e13e5289b11185b67cf4162b0@science.uva.nl> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1I8XWn-0002jA-4h for emacs-orgmode@gnu.org; Wed, 11 Jul 2007 04:26:29 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1I8XWm-0002iy-EY for emacs-orgmode@gnu.org; Wed, 11 Jul 2007 04:26:28 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1I8XWm-0002iv-9E for emacs-orgmode@gnu.org; Wed, 11 Jul 2007 04:26:28 -0400 Received: from smtp-vbr3.xs4all.nl ([194.109.24.23]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1I8XWl-00082q-Qq for emacs-orgmode@gnu.org; Wed, 11 Jul 2007 04:26:28 -0400 Received: from Barebusta.DecebalComp (DecebalComputing.xs4all.nl [213.84.157.201]) by smtp-vbr3.xs4all.nl (8.13.8/8.13.8) with ESMTP id l6B8QQ9Q087874 for ; Wed, 11 Jul 2007 10:26:26 +0200 (CEST) (envelope-from CecilWesterhof@xs4all.nl) In-Reply-To: <93de834e13e5289b11185b67cf4162b0@science.uva.nl> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: org-mode Op wo, 11-07-2007 te 08:15 +0200, schreef Carsten Dominik: > If you want to understand why things come out the way they > do, use formular debugging (this is an option in the menu, but > cou can also toggle it with `C-C {'). When you then execute > calculations in the table (for example with `C-u C-c C-c') > you will get detailed information about variable substitution, > and you will see the final expression that gets evaluated. That is a good tip. ;-} > For example, you are trying things like > > (and $1 $2 ... > > but of course both the empty string and the number 0 are > "true" in Lisp, the only thing false in Lisp is "nil". That explains my problems. > If you want to fix it, you can, by *really* taking control. > For example, define the following function that tests > if a value is not zero > > (defun nz (n) (not (= n 0.))) > > and then write your table like this: > > |---------+------+---------+--------+-------+----------+--------| > | kmstand | km's | prijs/l | liters | prijs | prijs/km | km/l | > |---------+------+---------+--------+-------+----------+--------| > | 155111 | | | | | | | > | 156146 | 1035 | 102.2 | 62.25 | 63.62 | 6.147 | 16.627 | > | | | | | | | | > |---------+------+---------+--------+-------+----------+--------| > #+TBLFM: $2='(if (and (nz @-1$-1) (nz $1) (> $1 @-1$-1)) (- $1 @-1$-1) > "");N::$5='(if (and (nz $3) (nz $4)) (format "%.2f" (/ (* $3 $4) 100)) > "");N::$6='(if (and (nz $2) (nz $5)) (format "%.3f" (/ (* $5 100) $2)) > "");N::$7='(if (and (nz $2) (nz $4)) (format "%.3f" (/ $2 $4)) "");N That works perfect. > Yes, those equations look longish - use the formula > editor to edit them. That is also a nice tool yes. > Also, consider to put the "#" marker in the first column, > to get this table to recompute automatically while > you step through with TAB. Use C-# in the first data line > to insert the "#" if you want to make sure that your > existing formulas are modified to reflect the new > column numbers. The result will be this: That is also very usefull. > Hope this helps. It certainly did. I made another improvement. It would be nice to have a notification when there is a problem with kmstand. I made the folowing: |---+------------+---------+-------------------+---------+--------+-------+----------+--------| | | datum | kmstand | km's | prijs/l | liters | prijs | prijs/km | km/l | |---+------------+---------+-------------------+---------+--------+-------+----------+--------| | # | | 155111 | Verkeerde kmstand | | | | | | | # | 2007-07-09 | 156146 | 1035 | 102.2 | 62.25 | 63.62 | 6.147 | 16.627 | | # | | 6953 | Verkeerde kmstand | | | | | | | # | | | | | | | | | |---+------------+---------+-------------------+---------+--------+-------+----------+--------| #+TBLFM: $4='(if (and (nz @-1$3) (nz $3)) (if (> $3 @-1$3) (- $3 @-1$3) "Verkeerde kmstand") "");N::$7='(if (and (nz $5) (nz $6)) (format "%.2f" (/ (* $5 $6) 100)) "");N::$8='(if (and (nz $4) (nz $7)) (format "%.3f" (/ (* $7 100) $4)) "");N::$9='(if (and (nz $4) (nz $6)) (format "%.3f" (/ $4 $6)) "");N In this example the first two digits of kmstand where not input at row 3 and you get a message. But you get also a message at the first row. Is it possible to circumvent this? Is it possible to define functions in an org-file? For example: it would be nice to have more extensive checking on the values. Also the nz could be defined. It is in my .emacs now, but when I transfer the file to another computer, there is a risk that it doe not work anymore. It would be nice if I did input kmstand that with tab you go to prijs/l. (Skipping fields with formula's.) And when giving tab on the field liters going to the field kmstand. Is that something that could be made? -- Cecil Westerhof