From: Michael Brand <michael.ch.brand@gmail.com>
To: "Thierry Pellé" <thierry.pelle@soliavos.fr>
Cc: Org Mode <emacs-orgmode@gnu.org>, Eric Schulte <schulte.eric@gmail.com>
Subject: Re: Computations on properties
Date: Thu, 10 Oct 2013 11:04:35 +0200 [thread overview]
Message-ID: <CALn3zoighym283homG5rdyfWsq9na363zFqL1iCe0TptibSYcQ@mail.gmail.com> (raw)
In-Reply-To: <loom.20131010T083410-221@post.gmane.org>
[-- 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)
prev parent reply other threads:[~2013-10-10 9:04 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CALn3zoighym283homG5rdyfWsq9na363zFqL1iCe0TptibSYcQ@mail.gmail.com \
--to=michael.ch.brand@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=schulte.eric@gmail.com \
--cc=thierry.pelle@soliavos.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.