Hi Thierry
On Thu, Oct 10, 2013 at 8:39 AM, Thierry Pellé
<[email protected]> 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
From 0b7caf6adfcab1a6ad2b1aa330e7bd15c3be33d3 Mon Sep 17 00:00:00 2001
From: Michael Brand <[email protected]>
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)