emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Problem with lisp code in spreadsheet
@ 2007-06-16 17:50 Cecil Westerhof
  2007-06-16 22:14 ` Carsten Dominik
  0 siblings, 1 reply; 4+ messages in thread
From: Cecil Westerhof @ 2007-06-16 17:50 UTC (permalink / raw)
  To: org-mode

In a row I have the following formula's:
  =$3
  ='(getHours $2);%.2f
  ='(/ 67 0.72);%.1f
  ='(/ $3 (getHours $2));%.1f
This gives:
  67
  0.72
  93.1
  0.0

I would expect the last two to return the same number. Why is this not
the case?

When I change the last formula to:
  ='(/ 67 (getHours $2));%.1f
I get:
  93.5

What is happening here?

-- 
Cecil Westerhof <CecilWesterhof@xs4all.nl>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Problem with lisp code in spreadsheet
  2007-06-16 17:50 Problem with lisp code in spreadsheet Cecil Westerhof
@ 2007-06-16 22:14 ` Carsten Dominik
  2007-06-17  6:22   ` Cecil Westerhof
  0 siblings, 1 reply; 4+ messages in thread
From: Carsten Dominik @ 2007-06-16 22:14 UTC (permalink / raw)
  To: Cecil Westerhof; +Cc: org-mode


On Jun 16, 2007, at 19:50, Cecil Westerhof wrote:

> In a row I have the following formula's:
>   =$3
>   ='(getHours $2);%.2f
>   ='(/ 67 0.72);%.1f
>   ='(/ $3 (getHours $2));%.1f
> This gives:
>   67
>   0.72
>   93.1
>   0.0
>
> I would expect the last two to return the same number. Why is this not
> the case?
>
> When I change the last formula to:
>   ='(/ 67 (getHours $2));%.1f
> I get:
>   93.5
>
> What is happening here?

Since I don't know exactly what getHours does, I cannot be sure.
The most likely reason though is that $3 and $2 are interpolated into
Lisp expressions as strings, not as numbers.

See the discussion of the N mode flag in

http://staff.science.uva.nl/~dominik/Tools/org/org.html#Formula-syntax- 
for-Lisp

- Carsten

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Problem with lisp code in spreadsheet
  2007-06-16 22:14 ` Carsten Dominik
@ 2007-06-17  6:22   ` Cecil Westerhof
  2007-06-17  9:56     ` Carsten Dominik
  0 siblings, 1 reply; 4+ messages in thread
From: Cecil Westerhof @ 2007-06-17  6:22 UTC (permalink / raw)
  To: org-mode

Op zo, 17-06-2007 te 00:14 +0200, schreef Carsten Dominik:
> > In a row I have the following formula's:
> >   =$3
> >   ='(getHours $2);%.2f
> >   ='(/ 67 0.72);%.1f
> >   ='(/ $3 (getHours $2));%.1f
> > This gives:
> >   67
> >   0.72
> >   93.1
> >   0.0
> >
> > I would expect the last two to return the same number. Why is this not
> > the case?
> >
> > When I change the last formula to:
> >   ='(/ 67 (getHours $2));%.1f
> > I get:
> >   93.5
> >
> > What is happening here?
> 
> Since I don't know exactly what getHours does, I cannot be sure.
> The most likely reason though is that $3 and $2 are interpolated into
> Lisp expressions as strings, not as numbers.

The tabel:
        |--------+------+----+-----+------+----+------|
        | Arnhem | 0:43 | 67 | 0.0 | 93.1 | 67 | 0.72 |
        |--------+------+----+-----+------+----+------|
        #+TBLFM: $4='(/ $3 (getHours $2));N%.1f::$5='(/ 67 0.72);%.1f::$6=$3::$7='(getHours $2);%.2f::

getHours:
        (defun getHours(time)
          (interactive "sHH:MM: ")
          (let ((timelist (split-string time ":")))
            (+
              (string-to-number (car timelist))
              (/
                (string-to-number (cadr timelist))
                60.0
              )
            )
          )
        )

The strange thing is that $3 is 67 and when I change $3 to 67 it works.

Even changing the formul to:
	='(/ (string-to-number $3) (getHours $2));N%.1f
does not work.

> See the discussion of the N mode flag in
> 
> http://staff.science.uva.nl/~dominik/Tools/org/org.html#Formula-syntax- 
> for-Lisp

The problem is with $3, so I would not know how to use that. :-{

-- 
Cecil Westerhof <CecilWesterhof@xs4all.nl>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Problem with lisp code in spreadsheet
  2007-06-17  6:22   ` Cecil Westerhof
@ 2007-06-17  9:56     ` Carsten Dominik
  0 siblings, 0 replies; 4+ messages in thread
From: Carsten Dominik @ 2007-06-17  9:56 UTC (permalink / raw)
  To: Cecil Westerhof; +Cc: org-mode

On Jun 17, 2007, at 8:22, Cecil Westerhof wrote:

> Op zo, 17-06-2007 te 00:14 +0200, schreef Carsten Dominik:
>>> In a row I have the following formula's:
>>>   =$3
>>>   ='(getHours $2);%.2f
>>>   ='(/ 67 0.72);%.1f
>>>   ='(/ $3 (getHours $2));%.1f
>>> This gives:
>>>   67
>>>   0.72
>>>   93.1
>>>   0.0
>>>
>>> I would expect the last two to return the same number. Why is this  
>>> not
>>> the case?
>>>
>>> When I change the last formula to:
>>>   ='(/ 67 (getHours $2));%.1f
>>> I get:
>>>   93.5
>>>
>>> What is happening here?
>>
>> Since I don't know exactly what getHours does, I cannot be sure.
>> The most likely reason though is that $3 and $2 are interpolated into
>> Lisp expressions as strings, not as numbers.
>
> The tabel:
>         |--------+------+----+-----+------+----+------|
>         | Arnhem | 0:43 | 67 | 0.0 | 93.1 | 67 | 0.72 |
>         |--------+------+----+-----+------+----+------|
>         #+TBLFM: $4='(/ $3 (getHours $2));N%.1f::$5='(/ 67  
> 0.72);%.1f::$6=$3::$7='(getHours $2);%.2f::
>
> getHours:
>         (defun getHours(time)
>           (interactive "sHH:MM: ")
>           (let ((timelist (split-string time ":")))
>             (+
>               (string-to-number (car timelist))
>               (/
>                 (string-to-number (cadr timelist))
>                 60.0
>               )
>             )
>           )
>         )
>
> The strange thing is that $3 is 67 and when I change $3 to 67 it works.


What is going wrong is that you want $2 to be interpreted as a string,
and $3 as a number.  So you could leave off the N flag again and write
(string-to-number $3)

Hmmm, maybe this is not completely satisfying now, maybe it would
be good to have replacements literally and then to write (getHours  
"$2"), that
might also be an option.

Needs more thinking.

- Carsten


>
> Even changing the formul to:
> 	='(/ (string-to-number $3) (getHours $2));N%.1f
> does not work.
>
>> See the discussion of the N mode flag in
>>
>> http://staff.science.uva.nl/~dominik/Tools/org/org.html#Formula- 
>> syntax-
>> for-Lisp
>
> The problem is with $3, so I would not know how to use that. :-{
>
> -- 
> Cecil Westerhof <CecilWesterhof@xs4all.nl>
>
>
>
> _______________________________________________
> Emacs-orgmode mailing list
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
>
>

--
Carsten Dominik
Sterrenkundig Instituut "Anton Pannekoek"
Universiteit van Amsterdam
Kruislaan 403
NL-1098SJ Amsterdam
phone: +31 20 525 7477

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2007-06-17  9:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-16 17:50 Problem with lisp code in spreadsheet Cecil Westerhof
2007-06-16 22:14 ` Carsten Dominik
2007-06-17  6:22   ` Cecil Westerhof
2007-06-17  9:56     ` Carsten Dominik

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).