From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: Re: Calling/using named babel code blocks Date: Wed, 18 Dec 2019 13:33:13 -0500 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="000000000000200b8d0599feae6e" Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:41818) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ihe8X-00043d-QR for emacs-orgmode@gnu.org; Wed, 18 Dec 2019 13:33:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ihe8W-0004Ja-8k for emacs-orgmode@gnu.org; Wed, 18 Dec 2019 13:33:29 -0500 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]:51795) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ihe8V-00048M-Md for emacs-orgmode@gnu.org; Wed, 18 Dec 2019 13:33:28 -0500 Received: by mail-wm1-x32b.google.com with SMTP id d73so2898574wmd.1 for ; Wed, 18 Dec 2019 10:33:27 -0800 (PST) In-Reply-To: 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: Lawrence Bottorff Cc: emacs-orgmode Mailinglist --000000000000200b8d0599feae6e Content-Type: text/plain; charset="UTF-8" I think you want: #+name: my-random-gen #+header: :var n=0 :var lim=0 #+BEGIN_SRC emacs-lisp (loop repeat n collect (random* lim)) #+END_SRC and this various versions of this #+BEGIN_SRC emacs-lisp :var results=my-random-gen(n=5, lim=1.0) results #+END_SRC #+RESULTS: | 0.27765703201293945 | 0.7524830102920532 | 0.854852557182312 | 0.22202050685882568 | 0.604256272315979 | John ----------------------------------- Professor John Kitchin Doherty Hall A207F Department of Chemical Engineering Carnegie Mellon University Pittsburgh, PA 15213 412-268-7803 @johnkitchin http://kitchingroup.cheme.cmu.edu On Wed, Dec 18, 2019 at 12:11 PM Lawrence Bottorff wrote: > I thought I understood "metaprogramming," i.e., creating generic code > blocks that can be called by any other code block regardless of programming > language -- but apparently I don't. I have this > > #+name: my-random-gen > #+header: :var n=0 :var lim=0 > #+BEGIN_SRC emacs-lisp > (loop repeat n collect (random* lim)) > #+END_SRC > > and I have the variables initialized to zero. But now I don't know how to > call it with another code block. I've tried various versions of this > > #+BEGIN_SRC emacs-lisp > my-random-gen(5 1.0) > #+END_SRC > > and this various versions of this > > #+BEGIN_SRC emacs-lisp :var results=my-random-gen() :var n=5 :var lim=1.0 > results > #+END_SRC > > to no avail. What am I missing? How can I actually use, call my-random-gen > in other code blocks? > > LB > > > --000000000000200b8d0599feae6e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I think you want:


#+name: my-random= -gen
#+header: :var n=3D0 :var lim=3D0
#+BEGIN_SRC emacs-lisp
(loo= p repeat n collect (random* lim))
#+END_SRC

and this various vers= ions of this

#+BEGIN_SRC emacs-lisp :var results=3Dmy-random-gen(n= =3D5, lim=3D1.0)
results
#+END_SRC

#+RESULTS:
| 0.27765703= 201293945 | 0.7524830102920532 | 0.854852557182312 | 0.22202050685882568 | = 0.604256272315979 |

<= /div>

John

--------------= ---------------------
Professor John Kitchin=C2=A0
Doherty Hall A207F=
Department of Chemical Engineering
Carnegie Mellon University
Pit= tsburgh, PA 15213
412-268-7803


On W= ed, Dec 18, 2019 at 12:11 PM Lawrence Bottorff <borgauf@gmail.com> wrote:
I thought I understood "metaprogramming," i.e., creating gen= eric code blocks that can be called by any other code block regardless of p= rogramming language -- but apparently I don't. I have this
<= font face=3D"arial, sans-serif">
=C2=A0#+name: my-random-gen
#+header: :var n=3D0 :var lim=3D0
#+BE= GIN_SRC emacs-lisp
(loop repeat n collect (random* lim))
#+END_SRC

and I have the variables initialized to zero. But n= ow I don't know how to call it with another code block. I've tried = various versions of this

= #+BEGIN_SRC emacs-lisp
my-ran= dom-gen(5 1.0)
#+END_SRC

and this various versions of this

#+BEGIN_SRC emacs-lisp :var result= s=3Dmy-random-gen() :var n=3D5 :var lim=3D1.0
results
#+END_SRC

to no avail. What am I=C2=A0missing? How can= I actually use, call=C2=A0my-random-gen in= other code blocks?

LB

--000000000000200b8d0599feae6e--