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 <borg...@gmail.com>
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
>
>
>

Reply via email to