all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Computations on properties
@ 2013-10-09 12:19 Thierry Pellé
  2013-10-09 12:50 ` Thorsten Jolitz
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Thierry Pellé @ 2013-10-09 12:19 UTC (permalink / raw)
  To: emacs-orgmode

Hi,
  I'm seeking how to do something like that

Let the following text inserted in an org-mode file

* Mean Calculation
 :PROPERTIES:
 :VAL1: 5
 :VAL2: 10
 :COEF: 10
 :END:

I would like to append the result of a computation 
like RES=(VAL1*COEF+VAL2)/(COEF+1) 

Something like 
* Mean Calculation
...
  :END:

Mean Calculation=RES (where RES is the value of the result)

I think to do this with a python script but is there a more org-mode/emacs
method to do it?

Thanks
Thierry 

PS: I don't want to use org spreadsheet

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

* Re: Computations on properties
  2013-10-09 12:19 Computations on properties Thierry Pellé
@ 2013-10-09 12:50 ` Thorsten Jolitz
  2013-10-09 13:32   ` Thierry Pellé
  2013-10-09 15:29 ` Eric Abrahamsen
  2013-10-09 19:27 ` Michael Brand
  2 siblings, 1 reply; 11+ messages in thread
From: Thorsten Jolitz @ 2013-10-09 12:50 UTC (permalink / raw)
  To: emacs-orgmode

Thierry Pellé <thierry.pelle@soliavos.fr> writes:

Hi,
>   I'm seeking how to do something like that
>
> Let the following text inserted in an org-mode file
>
> * Mean Calculation
>  :PROPERTIES:
>  :VAL1: 5
>  :VAL2: 10
>  :COEF: 10
>  :END:
>
> I would like to append the result of a computation 
> like RES=(VAL1*COEF+VAL2)/(COEF+1) 
>
> Something like 
> * Mean Calculation
> ...
>   :END:
>
> Mean Calculation=RES (where RES is the value of the result)
>
> I think to do this with a python script but is there a more org-mode/emacs
> method to do it?
>
> Thanks
> Thierry 
>
> PS: I don't want to use org spreadsheet

But that would probably be the appropriate tool. Otherwise you could use
the property API in an elisp program

,------------------------------------------------------
| http://orgmode.org/manual/Using-the-property-API.html
`------------------------------------------------------

to read out the property values. Then do the calculation and finally add
a new property with the result.

-- 
cheers,
Thorsten

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

* Re: Computations on properties
  2013-10-09 12:50 ` Thorsten Jolitz
@ 2013-10-09 13:32   ` Thierry Pellé
  0 siblings, 0 replies; 11+ messages in thread
From: Thierry Pellé @ 2013-10-09 13:32 UTC (permalink / raw)
  To: emacs-orgmode

Thank you for the reply

> > PS: I don't want to use org spreadsheet
> 
> But that would probably be the appropriate tool.

I know, but I can't figure out how to extract the speadsheet computed value
into the text...

> Otherwise you could use
> the property API in an elisp program
> 
> ,------------------------------------------------------
> | http://orgmode.org/manual/Using-the-property-API.html
> `------------------------------------------------------
> 
> to read out the property values. Then do the calculation and finally add
> a new property with the result.
> 
I look at it.
Thanks.

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

* Re: Computations on properties
  2013-10-09 12:19 Computations on properties Thierry Pellé
  2013-10-09 12:50 ` Thorsten Jolitz
@ 2013-10-09 15:29 ` Eric Abrahamsen
  2013-10-09 17:12   ` Thorsten Jolitz
  2013-10-09 19:27 ` Michael Brand
  2 siblings, 1 reply; 11+ messages in thread
From: Eric Abrahamsen @ 2013-10-09 15:29 UTC (permalink / raw)
  To: emacs-orgmode

Thierry Pellé <thierry.pelle@soliavos.fr> writes:

> Hi,
>   I'm seeking how to do something like that
>
> Let the following text inserted in an org-mode file
>
> * Mean Calculation
>  :PROPERTIES:
>  :VAL1: 5
>  :VAL2: 10
>  :COEF: 10
>  :END:
>
> I would like to append the result of a computation 
> like RES=(VAL1*COEF+VAL2)/(COEF+1) 
>
> Something like 
> * Mean Calculation
> ...
>   :END:
>
> Mean Calculation=RES (where RES is the value of the result)
>
> I think to do this with a python script but is there a more org-mode/emacs
> method to do it?

Sometimes I think it would be nice to have a way to draw property values
directly into a babel block, the way you can with table data. Sort of
like:

* Heading
  :PROPERTIES:
  :ID:       3f78f08a-ccca-4fc0-aba9-2a192f7a0e5a
  :foo:  5
  :bar:  puppy
  :END:

#+BEGIN_SRC emacs-lisp :var alist=3f78f08a-ccca-4fc0-aba9-2a192f7a0e5a

And in the block, the "alist" variable would look like '(:foo 5 :bar
"puppy").

What would be even better would be to run a tags search on matching
headlines and feed all property drawers into a single block, as a list
of alists. Just thinking out loud...

E

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

* Re: Computations on properties
  2013-10-09 15:29 ` Eric Abrahamsen
@ 2013-10-09 17:12   ` Thorsten Jolitz
  2013-10-09 18:21     ` Eric Abrahamsen
  2013-10-09 18:23     ` Eric Schulte
  0 siblings, 2 replies; 11+ messages in thread
From: Thorsten Jolitz @ 2013-10-09 17:12 UTC (permalink / raw)
  To: emacs-orgmode

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> Thierry Pellé <thierry.pelle@soliavos.fr> writes:
>
>> Hi,
>>   I'm seeking how to do something like that
>>
>> Let the following text inserted in an org-mode file
>>
>> * Mean Calculation
>>  :PROPERTIES:
>>  :VAL1: 5
>>  :VAL2: 10
>>  :COEF: 10
>>  :END:
>>
>> I would like to append the result of a computation 
>> like RES=(VAL1*COEF+VAL2)/(COEF+1) 
>>
>> Something like 
>> * Mean Calculation
>> ...
>>   :END:
>>
>> Mean Calculation=RES (where RES is the value of the result)
>>
>> I think to do this with a python script but is there a more org-mode/emacs
>> method to do it?
>
> Sometimes I think it would be nice to have a way to draw property values
> directly into a babel block, the way you can with table data. Sort of
> like:
>
> * Heading
>   :PROPERTIES:
>   :ID:       3f78f08a-ccca-4fc0-aba9-2a192f7a0e5a
>   :foo:  5
>   :bar:  puppy
>   :END:
>
> #+BEGIN_SRC emacs-lisp :var alist=3f78f08a-ccca-4fc0-aba9-2a192f7a0e5a
>
> And in the block, the "alist" variable would look like '(:foo 5 :bar
> "puppy").
>
> What would be even better would be to run a tags search on matching
> headlines and feed all property drawers into a single block, as a list
> of alists. Just thinking out loud...

This is probably not really what you want, but at least somehow related. I
would not know how to do this via source-block arguments, but maybe you can
use the results of one source-block (that produces the data) as input for
another source-block that does the real work. 

* Heading 1 :match:
  :PROPERTIES:
  :ID:       3f78f08a-ccca-4fc0-aba9-2a192f7a0e5a
  :foo:  5
  :bar:  puppy
  :END:

* Heading 2
  :PROPERTIES:
  :ID:       3f78f08a-ccca-4fc0-aba9-2a192f7a0e5b
  :foo:  6
  :bar: yuppy
  :END:


* Heading 3 :match:
  :PROPERTIES:
  :ID:       3f78f08a-ccca-4fc0-aba9-2a192f7a0e5c
  :foo:  7
  :bar:  hippie
  :END:


#+begin_src emacs-lisp :results raw
   (let ((lst))
      (org-map-entries
       (lambda () (cons (org-entry-properties) lst))
       "match" 'file))
#+end_src

#+results:
((((FILE . /home/tj/News/drafts/drafts/419) (TAGS . :match:) (ALLTAGS
. :match:) (BLOCKED . ) (ID . 3f78f08a-ccca-4fc0-aba9-2a192f7a0e5a) (foo . 5)
(bar . puppy) (CATEGORY . 419))) (((FILE . /home/tj/News/drafts/drafts/419)
(TAGS . :match:) (ALLTAGS . :match:) (BLOCKED . ) (ID .
3f78f08a-ccca-4fc0-aba9-2a192f7a0e5c) (foo . 7) (bar . hippie) (CATEGORY .
419))))

-- 
cheers,
Thorsten

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

* Re: Computations on properties
  2013-10-09 17:12   ` Thorsten Jolitz
@ 2013-10-09 18:21     ` Eric Abrahamsen
  2013-10-09 18:23     ` Eric Schulte
  1 sibling, 0 replies; 11+ messages in thread
From: Eric Abrahamsen @ 2013-10-09 18:21 UTC (permalink / raw)
  To: emacs-orgmode

Thorsten Jolitz <tjolitz@gmail.com> writes:

> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>
>> Thierry Pellé <thierry.pelle@soliavos.fr> writes:
>>
>>> Hi,
>>>   I'm seeking how to do something like that
>>>
>>> Let the following text inserted in an org-mode file
>>>
>>> * Mean Calculation
>>>  :PROPERTIES:
>>>  :VAL1: 5
>>>  :VAL2: 10
>>>  :COEF: 10
>>>  :END:
>>>
>>> I would like to append the result of a computation 
>>> like RES=(VAL1*COEF+VAL2)/(COEF+1) 
>>>
>>> Something like 
>>> * Mean Calculation
>>> ...
>>>   :END:
>>>
>>> Mean Calculation=RES (where RES is the value of the result)
>>>
>>> I think to do this with a python script but is there a more org-mode/emacs
>>> method to do it?
>>
>> Sometimes I think it would be nice to have a way to draw property values
>> directly into a babel block, the way you can with table data. Sort of
>> like:
>>
>> * Heading
>>   :PROPERTIES:
>>   :ID:       3f78f08a-ccca-4fc0-aba9-2a192f7a0e5a
>>   :foo:  5
>>   :bar:  puppy
>>   :END:
>>
>> #+BEGIN_SRC emacs-lisp :var alist=3f78f08a-ccca-4fc0-aba9-2a192f7a0e5a
>>
>> And in the block, the "alist" variable would look like '(:foo 5 :bar
>> "puppy").
>>
>> What would be even better would be to run a tags search on matching
>> headlines and feed all property drawers into a single block, as a list
>> of alists. Just thinking out loud...
>
> This is probably not really what you want, but at least somehow related. I
> would not know how to do this via source-block arguments, but maybe you can
> use the results of one source-block (that produces the data) as input for
> another source-block that does the real work. 

Sure, it's certainly doable, and in more than one way, but I think
that's part of the problem: the reason the table-to-src-block-var
process is so great is that it feels purpose-built to do what it does.
For properties you've got search, column view, and the API, but it never
quite feels like the potential is unlocked...

> * Heading 1 :match:
>   :PROPERTIES:
>   :ID:       3f78f08a-ccca-4fc0-aba9-2a192f7a0e5a
>   :foo:  5
>   :bar:  puppy
>   :END:
>
> * Heading 2
>   :PROPERTIES:
>   :ID:       3f78f08a-ccca-4fc0-aba9-2a192f7a0e5b
>   :foo:  6
>   :bar: yuppy
>   :END:
>
>
> * Heading 3 :match:
>   :PROPERTIES:
>   :ID:       3f78f08a-ccca-4fc0-aba9-2a192f7a0e5c
>   :foo:  7
>   :bar:  hippie
>   :END:
>
>
> #+begin_src emacs-lisp :results raw
>    (let ((lst))
>       (org-map-entries
>        (lambda () (cons (org-entry-properties) lst))
>        "match" 'file))
> #+end_src
>
> #+results:
> ((((FILE . /home/tj/News/drafts/drafts/419) (TAGS . :match:) (ALLTAGS
> . :match:) (BLOCKED . ) (ID . 3f78f08a-ccca-4fc0-aba9-2a192f7a0e5a) (foo . 5)
> (bar . puppy) (CATEGORY . 419))) (((FILE . /home/tj/News/drafts/drafts/419)
> (TAGS . :match:) (ALLTAGS . :match:) (BLOCKED . ) (ID .
> 3f78f08a-ccca-4fc0-aba9-2a192f7a0e5c) (foo . 7) (bar . hippie) (CATEGORY .
> 419))))

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

* Re: Computations on properties
  2013-10-09 17:12   ` Thorsten Jolitz
  2013-10-09 18:21     ` Eric Abrahamsen
@ 2013-10-09 18:23     ` Eric Schulte
  2013-10-10  4:52       ` Eric Abrahamsen
  1 sibling, 1 reply; 11+ messages in thread
From: Eric Schulte @ 2013-10-09 18:23 UTC (permalink / raw)
  To: Thorsten Jolitz; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 2736 bytes --]

Thorsten Jolitz <tjolitz@gmail.com> writes:

> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>
>> Thierry Pellé <thierry.pelle@soliavos.fr> writes:
>>
>>> Hi,
>>>   I'm seeking how to do something like that
>>>
>>> Let the following text inserted in an org-mode file
>>>
>>> * Mean Calculation
>>>  :PROPERTIES:
>>>  :VAL1: 5
>>>  :VAL2: 10
>>>  :COEF: 10
>>>  :END:
>>>
>>> I would like to append the result of a computation 
>>> like RES=(VAL1*COEF+VAL2)/(COEF+1) 
>>>
>>> Something like 
>>> * Mean Calculation
>>> ...
>>>   :END:
>>>
>>> Mean Calculation=RES (where RES is the value of the result)
>>>
>>> I think to do this with a python script but is there a more org-mode/emacs
>>> method to do it?
>>
>> Sometimes I think it would be nice to have a way to draw property values
>> directly into a babel block, the way you can with table data. Sort of
>> like:
>>
>> * Heading
>>   :PROPERTIES:
>>   :ID:       3f78f08a-ccca-4fc0-aba9-2a192f7a0e5a
>>   :foo:  5
>>   :bar:  puppy
>>   :END:
>>
>> #+BEGIN_SRC emacs-lisp :var alist=3f78f08a-ccca-4fc0-aba9-2a192f7a0e5a
>>
>> And in the block, the "alist" variable would look like '(:foo 5 :bar
>> "puppy").
>>
>> What would be even better would be to run a tags search on matching
>> headlines and feed all property drawers into a single block, as a list
>> of alists. Just thinking out loud...
>
> This is probably not really what you want, but at least somehow related. I
> would not know how to do this via source-block arguments, but maybe you can
> use the results of one source-block (that produces the data) as input for
> another source-block that does the real work. 
>
> * Heading 1 :match:
>   :PROPERTIES:
>   :ID:       3f78f08a-ccca-4fc0-aba9-2a192f7a0e5a
>   :foo:  5
>   :bar:  puppy
>   :END:
>
> * Heading 2
>   :PROPERTIES:
>   :ID:       3f78f08a-ccca-4fc0-aba9-2a192f7a0e5b
>   :foo:  6
>   :bar: yuppy
>   :END:
>
>
> * Heading 3 :match:
>   :PROPERTIES:
>   :ID:       3f78f08a-ccca-4fc0-aba9-2a192f7a0e5c
>   :foo:  7
>   :bar:  hippie
>   :END:
>
>
> #+begin_src emacs-lisp :results raw
>    (let ((lst))
>       (org-map-entries
>        (lambda () (cons (org-entry-properties) lst))
>        "match" 'file))
> #+end_src
>
> #+results:
> ((((FILE . /home/tj/News/drafts/drafts/419) (TAGS . :match:) (ALLTAGS
> . :match:) (BLOCKED . ) (ID . 3f78f08a-ccca-4fc0-aba9-2a192f7a0e5a) (foo . 5)
> (bar . puppy) (CATEGORY . 419))) (((FILE . /home/tj/News/drafts/drafts/419)
> (TAGS . :match:) (ALLTAGS . :match:) (BLOCKED . ) (ID .
> 3f78f08a-ccca-4fc0-aba9-2a192f7a0e5c) (foo . 7) (bar . hippie) (CATEGORY .
> 419))))

Or maybe something like the following...


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: property-computation.org --]
[-- Type: text/x-org, Size: 478 bytes --]

* Mean Calculation
 :PROPERTIES:
 :VAL1: 5
 :VAL2: 10
 :COEF: 10
 :END:

#+begin_src python :var props=(mapcar (lambda (p) (list (car p) (cdr p))) (org-entry-properties))
  return props
#+end_src

#+RESULTS:
| FILE     | /tmp/property-computation.org |
| BLOCKED  |                               |
| VAL1     |                             5 |
| VAL2     |                            10 |
| COEF     |                            10 |
| CATEGORY |          property-computation |

[-- Attachment #3: Type: text/plain, Size: 63 bytes --]


-- 
Eric Schulte
https://cs.unm.edu/~eschulte
PGP: 0x614CA05D

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

* Re: Computations on properties
  2013-10-09 12:19 Computations on properties Thierry Pellé
  2013-10-09 12:50 ` Thorsten Jolitz
  2013-10-09 15:29 ` Eric Abrahamsen
@ 2013-10-09 19:27 ` Michael Brand
  2013-10-10  6:39   ` Thierry Pellé
  2 siblings, 1 reply; 11+ messages in thread
From: Michael Brand @ 2013-10-09 19:27 UTC (permalink / raw)
  To: Thierry Pellé; +Cc: Org Mode

Hi Thierry

On Wed, Oct 9, 2013 at 2:19 PM, Thierry Pellé <thierry.pelle@soliavos.fr> wrote:
> Mean Calculation=RES (where RES is the value of the result)

One more variant would be to use inline source block calls either
interactively with C-c C-c or during export. An example with shell
(python would be very similar) or the built-in Emacs Lisp is in the
Emacs Regression Test ERT in the top heading "use case of reading
entry properties" here:
http://orgmode.org/w/?p=org-mode.git;a=blob;f=testing/examples/babel.org

Your use case, here with Emacs Lisp, would be e. g.:

--------------------------------
* Mean Calculation
  :PROPERTIES:
  :VAL1:     5
  :VAL2:     10
  :COEF:     10
  :END:

  Mean Calculation = call_mean() =5.454545454545454=

* code :noexport:
  #+NAME: mean
  #+HEADER: :var val1='nil
  #+HEADER: :var val2='nil
  #+HEADER: :var coef='nil
  #+BEGIN_SRC emacs-lisp :exports none
    (setq
     val1 (string-to-number (org-entry-get
                             org-babel-current-src-block-location "VAL1" t))
     val2 (string-to-number (org-entry-get
                             org-babel-current-src-block-location "VAL2" t))
     coef (string-to-number (org-entry-get
                             org-babel-current-src-block-location "COEF" t)))
    (/ (+ (* val1 coef) val2) (+ coef 1.0))
  #+END_SRC
--------------------------------

Michael

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

* Re: Computations on properties
  2013-10-09 18:23     ` Eric Schulte
@ 2013-10-10  4:52       ` Eric Abrahamsen
  0 siblings, 0 replies; 11+ messages in thread
From: Eric Abrahamsen @ 2013-10-10  4:52 UTC (permalink / raw)
  To: emacs-orgmode

Eric Schulte <schulte.eric@gmail.com> writes:

> Thorsten Jolitz <tjolitz@gmail.com> writes:
>
>> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>>
>>> Thierry Pellé <thierry.pelle@soliavos.fr> writes:
>>>
>>>> Hi,
>>>>   I'm seeking how to do something like that
>>>>
>>>> Let the following text inserted in an org-mode file
>>>>
>>>> * Mean Calculation
>>>>  :PROPERTIES:
>>>>  :VAL1: 5
>>>>  :VAL2: 10
>>>>  :COEF: 10
>>>>  :END:
>>>>
>>>> I would like to append the result of a computation 
>>>> like RES=(VAL1*COEF+VAL2)/(COEF+1) 
>>>>
>>>> Something like 
>>>> * Mean Calculation
>>>> ...
>>>>   :END:
>>>>
>>>> Mean Calculation=RES (where RES is the value of the result)
>>>>
>>>> I think to do this with a python script but is there a more org-mode/emacs
>>>> method to do it?
>>>
>>> Sometimes I think it would be nice to have a way to draw property values
>>> directly into a babel block, the way you can with table data. Sort of
>>> like:
>>>
>>> * Heading
>>>   :PROPERTIES:
>>>   :ID:       3f78f08a-ccca-4fc0-aba9-2a192f7a0e5a
>>>   :foo:  5
>>>   :bar:  puppy
>>>   :END:
>>>
>>> #+BEGIN_SRC emacs-lisp :var alist=3f78f08a-ccca-4fc0-aba9-2a192f7a0e5a
>>>
>>> And in the block, the "alist" variable would look like '(:foo 5 :bar
>>> "puppy").
>>>
>>> What would be even better would be to run a tags search on matching
>>> headlines and feed all property drawers into a single block, as a list
>>> of alists. Just thinking out loud...
>>
>> This is probably not really what you want, but at least somehow related. I
>> would not know how to do this via source-block arguments, but maybe you can
>> use the results of one source-block (that produces the data) as input for
>> another source-block that does the real work. 
>>
>> * Heading 1 :match:
>>   :PROPERTIES:
>>   :ID:       3f78f08a-ccca-4fc0-aba9-2a192f7a0e5a
>>   :foo:  5
>>   :bar:  puppy
>>   :END:
>>
>> * Heading 2
>>   :PROPERTIES:
>>   :ID:       3f78f08a-ccca-4fc0-aba9-2a192f7a0e5b
>>   :foo:  6
>>   :bar: yuppy
>>   :END:
>>
>>
>> * Heading 3 :match:
>>   :PROPERTIES:
>>   :ID:       3f78f08a-ccca-4fc0-aba9-2a192f7a0e5c
>>   :foo:  7
>>   :bar:  hippie
>>   :END:
>>
>>
>> #+begin_src emacs-lisp :results raw
>>    (let ((lst))
>>       (org-map-entries
>>        (lambda () (cons (org-entry-properties) lst))
>>        "match" 'file))
>> #+end_src
>>
>> #+results:
>> ((((FILE . /home/tj/News/drafts/drafts/419) (TAGS . :match:) (ALLTAGS
>> . :match:) (BLOCKED . ) (ID . 3f78f08a-ccca-4fc0-aba9-2a192f7a0e5a) (foo . 5)
>> (bar . puppy) (CATEGORY . 419))) (((FILE . /home/tj/News/drafts/drafts/419)
>> (TAGS . :match:) (ALLTAGS . :match:) (BLOCKED . ) (ID .
>> 3f78f08a-ccca-4fc0-aba9-2a192f7a0e5c) (foo . 7) (bar . hippie) (CATEGORY .
>> 419))))
>
> Or maybe something like the following...
>
> * Mean Calculation
>  :PROPERTIES:
>  :VAL1: 5
>  :VAL2: 10
>  :COEF: 10
>  :END:
>
> #+begin_src python :var props=(mapcar (lambda (p) (list (car p) (cdr p))) (org-entry-properties))
>   return props
> #+end_src

This is very cool! Thanks.

> #+RESULTS:
> | FILE     | /tmp/property-computation.org |
> | BLOCKED  |                               |
> | VAL1     |                             5 |
> | VAL2     |                            10 |
> | COEF     |                            10 |
> | CATEGORY |          property-computation |

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

* Re: Computations on properties
  2013-10-09 19:27 ` Michael Brand
@ 2013-10-10  6:39   ` Thierry Pellé
  2013-10-10  9:04     ` Michael Brand
  0 siblings, 1 reply; 11+ messages in thread
From: Thierry Pellé @ 2013-10-10  6:39 UTC (permalink / raw)
  To: emacs-orgmode

After some tests :
==> the idea of Michael
> --------------------------------
> * Mean Calculation
>   :PROPERTIES:
>   :VAL1:     5
>   :VAL2:     10
>   :COEF:     10
>   :END:
> 
>   Mean Calculation = call_mean() =5.454545454545454=
> 
> * code :noexport:
>   #+NAME: mean
>   #+HEADER: :var val1='nil
>   #+HEADER: :var val2='nil
>   #+HEADER: :var coef='nil
>   #+BEGIN_SRC emacs-lisp :exports none
>     (setq
>      val1 (string-to-number (org-entry-get
>                              org-babel-current-src-block-location "VAL1" t))
>      val2 (string-to-number (org-entry-get
>                              org-babel-current-src-block-location "VAL2" t))
>      coef (string-to-number (org-entry-get
>                              org-babel-current-src-block-location "COEF" t)))
>     (/ (+ (* val1 coef) val2) (+ coef 1.0))
>   #+END_SRC
> --------------------------------
 
give an error ( "Symbol's value as variable is void:
org-babel-current-src-block-location")

==> After some tests, it works in changing the "setq" part as
 val1 (or val1 (string-to-number
            (org-entry-get org-babel-current-src-block-location "VAL1" t)
                ))

I can't figure out why...

==> I will try with python...

Thanks
 

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

* Re: Computations on properties
  2013-10-10  6:39   ` Thierry Pellé
@ 2013-10-10  9:04     ` Michael Brand
  0 siblings, 0 replies; 11+ messages in thread
From: Michael Brand @ 2013-10-10  9:04 UTC (permalink / raw)
  To: Thierry Pellé; +Cc: Org Mode, Eric Schulte

[-- Attachment #1: Type: text/plain, Size: 2259 bytes --]

Hi Thierry

On Thu, Oct 10, 2013 at 8:39 AM, Thierry Pellé
<thierry.pelle@soliavos.fr> wrote:
> After some tests :
> ==> the idea of Michael
>> --------------------------------
>> * Mean Calculation
>>   :PROPERTIES:
>>   :VAL1:     5
>>   :VAL2:     10
>>   :COEF:     10
>>   :END:
>>
>>   Mean Calculation = call_mean() =5.454545454545454=
>>
>> * code :noexport:
>>   #+NAME: mean
>>   #+HEADER: :var val1='nil
>>   #+HEADER: :var val2='nil
>>   #+HEADER: :var coef='nil
>>   #+BEGIN_SRC emacs-lisp :exports none
>>     (setq
>>      val1 (string-to-number (org-entry-get
>>                              org-babel-current-src-block-location "VAL1" t))
>>      val2 (string-to-number (org-entry-get
>>                              org-babel-current-src-block-location "VAL2" t))
>>      coef (string-to-number (org-entry-get
>>                              org-babel-current-src-block-location "COEF" t)))
>>     (/ (+ (* val1 coef) val2) (+ coef 1.0))
>>   #+END_SRC
>> --------------------------------
>
> give an error ( "Symbol's value as variable is void:
> org-babel-current-src-block-location")

This I would expect from an org-version older than 8.1. Check

    C-h v org-babel-current-src-block-location
    M-x org-version

But if you did not change the version there might be some problem
before the first loading of ob-core.el. If you can reproduce it, maybe
with a fresh started Emacs, I hope that someone more familiar with
autoload etc. than me can help.

> ==> After some tests, it works in changing the "setq" part as
>  val1 (or val1 (string-to-number
>             (org-entry-get org-babel-current-src-block-location "VAL1" t)
>                 ))

This does still not deal with all cases. As you seem to dive deeper
please forget my simplified version posted earlier and see
testing/examples/babel.org.

> I can't figure out why...

See the attached patch that adds comments to
testing/examples/babel.org for the two "or" and more.

CCed Eric Schulte who I would like to ask to review and apply the patch.

> ==> I will try with python...

Start from the shell example in testing/examples/babel.org

Did you check if you need the t or nil for org-entry-get?

Michael

[-- Attachment #2: 0001-Babel-add-comments-to-ERT-for-reading-properties.patch.txt --]
[-- Type: text/plain, Size: 1632 bytes --]

From 0b7caf6adfcab1a6ad2b1aa330e7bd15c3be33d3 Mon Sep 17 00:00:00 2001
From: Michael Brand <michael.ch.brand@gmail.com>
Date: Thu, 10 Oct 2013 11:02:19 +0200
Subject: [PATCH] Babel: add comments to ERT for reading properties

* testing/examples/babel.org (use case of reading entry properties):
Add comments to function definitions.
---
 testing/examples/babel.org | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/testing/examples/babel.org b/testing/examples/babel.org
index b1f1702..5c71834 100644
--- a/testing/examples/babel.org
+++ b/testing/examples/babel.org
@@ -413,6 +413,9 @@ Note: Just export of a property can be done with a macro: {{{property(a)}}}.
 
 **** function definition
 
+comments for ":var":
+- The "or" is to deal with a property not present.
+- The t is to get property inheritance.
 #+NAME: src_block_location_shell
 #+HEADER: :var a=(or (org-entry-get org-babel-current-src-block-location "a" t) "0")
 #+HEADER: :var b=(or (org-entry-get org-babel-current-src-block-location "b" t) "0")
@@ -433,6 +436,11 @@ Note: Just export of a property can be done with a macro: {{{property(a)}}}.
 #+HEADER: :var e='nil
 #+BEGIN_SRC emacs-lisp :exports results
   (setq
+   ;; - The first `or' together with ":var <var>='nil' is to check for
+   ;;   a value bound from an optional call argument, in the examples
+   ;;   here: c=5, e=6
+   ;; - The second `or' is to deal with a property not present
+   ;; - The t is to get property inheritance
    a (or a (string-to-number
             (or (org-entry-get org-babel-current-src-block-location "a" t)
                 "0")))
-- 
1.7.12.4 (Apple Git-37)


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

end of thread, other threads:[~2013-10-10  9:04 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-09 12:19 Computations on properties Thierry Pellé
2013-10-09 12:50 ` Thorsten Jolitz
2013-10-09 13:32   ` Thierry Pellé
2013-10-09 15:29 ` Eric Abrahamsen
2013-10-09 17:12   ` Thorsten Jolitz
2013-10-09 18:21     ` Eric Abrahamsen
2013-10-09 18:23     ` Eric Schulte
2013-10-10  4:52       ` Eric Abrahamsen
2013-10-09 19:27 ` Michael Brand
2013-10-10  6:39   ` Thierry Pellé
2013-10-10  9:04     ` Michael Brand

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.