From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ken Mankoff Subject: Re: Modify a variable before it is passed to babel (or exported)? Date: Mon, 16 Sep 2019 13:02:43 -0700 Message-ID: <87pnk0m2lf.fsf@gmail.com> References: <87v9ts5f8a.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:50138) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i9xD4-0004Lr-Hl for emacs-orgmode@gnu.org; Mon, 16 Sep 2019 16:02:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i9xD1-0007fR-Nd for emacs-orgmode@gnu.org; Mon, 16 Sep 2019 16:02:54 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]:39695) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i9xD1-0007er-Gz for emacs-orgmode@gnu.org; Mon, 16 Sep 2019 16:02:51 -0400 Received: by mail-pl1-x629.google.com with SMTP id bd8so379552plb.6 for ; Mon, 16 Sep 2019 13:02:51 -0700 (PDT) Received: from geus3064linuxwsm (161.11.27.136.in-addr.arpa. [136.27.11.161]) by smtp.gmail.com with ESMTPSA id cx22sm429453pjb.19.2019.09.16.13.02.49 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 16 Sep 2019 13:02:49 -0700 (PDT) In-reply-to: <87v9ts5f8a.fsf@gmail.com> 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: org-mode-email Hello, I solved this with (org-sbe). For example, using "add-one" and "table" from the original email #+Name: test-add-one #+BEGIN_SRC python :results output values :var data=(org-sbe add-one (data table)) print(data) #+END_SRC #+RESULTS: test-add-one : 43 Or src_elisp{(org-sbe add-one (data table))} {{{results(=43=)}}} -k. On 2019-09-16 at 10:21 -07, Ken Mankoff wrote... > I'd like to modify a variable with a babel block before another block > sees the variable. For example, I always want to add one to a > variable: > > #+NAME: add-one > #+BEGIN_SRC bash :results verbatim :var data=0 > data=$(( data + 1 )) > echo $data > #+END_SRC > > #+RESULTS: add_one > : 1 > > Test it: > > #+CALL: add_one(data=42) > > #+RESULTS: > : 43 > > Can I use =add_one= to modify data passed elsewhere? > > For example, given > > #+NAME: table > | 42 | > > I'm having trouble defining a =print_table= function that prints 43, using the =add_one= either via :prologue or <> or some other method. Preferably prologue because then the add_one function could be in a different language. > > > I can get halfway to what I want with a :post option, but need this to be a :pre or :prologue. Example using :post > > #+NAME: python_using_add_one > #+BEGIN_SRC python :results output values :post add-one(data=*this*) > print(42) > #+END_SRC > > #+RESULTS: python_using_add_one > : 43 > > Any suggestions how to use this feature with :pre or :prologue? > > Thanks, > > -k