From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michael Welle Subject: Re: Calc: Multiply time (hours) with a float Date: Mon, 19 Sep 2016 15:49:33 +0200 Message-ID: <87shswkniq.fsf@luisa.c0t0d0s0.de> References: <2016-09-08T10-32-27@devnull.Karl-Voit.at> <2016-09-11T13-43-22@devnull.Karl-Voit.at> <87oa3u1vpn.fsf@luisa.c0t0d0s0.de> <2016-09-18T18-32-24@devnull.Karl-Voit.at> <874m5cs7tq.fsf@luisa.c0t0d0s0.de> <87oa3kqsy3.fsf@luisa.c0t0d0s0.de> <2016-09-19T13-38-25@devnull.Karl-Voit.at> <87a8f4m596.fsf@luisa.c0t0d0s0.de> <2016-09-19T14-57-54@devnull.Karl-Voit.at> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:49529) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1blyx5-0001ia-3s for emacs-orgmode@gnu.org; Mon, 19 Sep 2016 09:49:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1blywx-0004p8-TU for emacs-orgmode@gnu.org; Mon, 19 Sep 2016 09:49:42 -0400 Received: from mout.gmx.net ([212.227.15.19]:50368) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1blywx-0004of-Iv for emacs-orgmode@gnu.org; Mon, 19 Sep 2016 09:49:35 -0400 Received: from stella.c0t0d0s0.de ([88.66.7.109]) by mail.gmx.com (mrgmx002) with ESMTPSA (Nemesis) id 0MYwyp-1bXsJ31IHL-00VjYt for ; Mon, 19 Sep 2016 15:49:34 +0200 Received: from Stella (stella.c0t0d0s0.de [192.168.42.1]) by stella.c0t0d0s0.de (Postfix) with ESMTP id 579C6C4264 for ; Mon, 19 Sep 2016 15:49:33 +0200 (CEST) In-Reply-To: <2016-09-19T14-57-54@devnull.Karl-Voit.at> (Karl Voit's message of "Mon, 19 Sep 2016 15:18:16 +0200") 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: emacs-orgmode@gnu.org Hello, Karl Voit writes: > * Michael Welle wrote: >> >> Karl Voit writes: >> >>>> [...] >>>>> #+TBLFM: @2$3='(* $2 (org-time-string-to-hours "$1"));L >>>> or converting $2 to a number before the calculation should work also, >>>> but is more to write ;). >>> >>> Hm. I still got #ERROR. I reduced my issue to calculate the float (for hours) >>> without multiplying it with "value": >> strange. I use the current Org version from git and Emacs 25.1. >> >>> | time [h:m:s] | value | product | >>> |--------------+---------+---------| >>> | 09:15:00 | 2.54321 | #ERROR | >>> >>> #+TBLFM: @2$3='(org-time-string-to-hours $1) >> That works for me. The default interpretation of $1 is used and >> therefore the value is fed into o-t-s-t-h as string. > > OK, this is my current issue then. The o-t-s-t-s function expect it to be a string, doesn't it? You test it with (stringp s) there. [...] >>> #+TBLFM: @2$3='(org-time-string-to-hours "$1");N >> Here you ask for interpretation as numbers. So the o-t-s-t-h function >> sees a stringified 9 as it's parameter value. Near, but still no t-shirt ;). > > I was wondering whether or not the stringification is done before or > after the number-conversion - as a test. It's an #ERROR anyway. The double quotes around $1 make it a string and your function parameter named s is of type string. As I said, your function sees a "9" in this variant and isn't prepared to work with that as input. That surely results in an error. >>> ... each of the TBLFM results in the same error. >> Well, none of them looks like the one I wrote: >> >> #+TBLFM: @2$3='(* $2 (org-time-string-to-hours "$1"));L > > ... which I tried first, got an #ERROR and analyzed the issue. > Narrowing down to '(org-time-string-to-hours $1) is my issue since > I now understand the handling of $2 which is according to the > documentation. > >> You said, that gives an error, too. I have no idea, why. You can use >> (message...) and (type-of ...) to look at the types and values that you >> feed into your functions. Maybe that gives some insight? > > (type-of ...) -> very helpful > > | time [h:m:s] | value | product | > |--------------+---------+---------| > | 09:15:00 | 2.54321 | #ERROR | > > #+TBLFM: @2$3='(message (type-of (org-time-string-to-hours $1))) > #+TBLFM: @2$3='(type-of (org-time-string-to-hours $1)) Try (message "type: %s" (type-of (org-time-string-to-hours $1))) > ... both formulas lead to #ERROR in @2$3 with no message in the > *Message* buffer. > > From my understanding, the first one should have caused an output of > the type in the *Message* buffer and the second one should have > placed something like "integer" into @2$3. Am I correct? In the table above both formulas place the value of the evaluated form in the product cell of the table. If you change the message example as suggested above, the product cell will contain something like "type: float", the second formula will insert just the type name: "float" in that case. >> The variant with converting $2 to a number is: >> #+TBLFM: @2$3='(* (string-to-number $2) (org-time-string-to-hours $1)) > > Since the issue is with $1, the (string-to-number $2) (which is > working) doesn't fix the #ERROR issue of $1 :-( You can put (message "type: '%s' value '%s'" (type-of s) s) into your o-t-s-t-seconds function, right before the cond form. That should print out a type of string and a value that can be processed by the logic of that function, i.e. just "9" doesn't work, because of the regexp you use as conditions. > Thank you *very* much for your explanations! I (and hopefully many > others as well) am learning a lot here. What I find a bit strange is that things that work for me, doesn't work in your environment. At first glance your function doesn't look so special, IMO. Regards hmw