[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Calling/using named babel code blocks
From: |
Berry, Charles |
Subject: |
Re: Calling/using named babel code blocks |
Date: |
Wed, 18 Dec 2019 18:03:07 +0000 |
> On Dec 18, 2019, at 9:10 AM, Lawrence Bottorff <address@hidden> 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?
>
Do these help?
#+BEGIN_SRC emacs-lisp :noweb yes
'<<my-random-gen(5, 1.0)>>
#+END_SRC
#+BEGIN_SRC emacs-lisp :var mrg=my-random-gen(5, 1.0)
mrg
#+END_SRC
Chuck