emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Berry, Charles" <ccberry@health.ucsd.edu>
To: Lawrence Bottorff <borgauf@gmail.com>
Cc: emacs-orgmode Mailinglist <emacs-orgmode@gnu.org>
Subject: Re: Calling/using named babel code blocks
Date: Wed, 18 Dec 2019 18:03:07 +0000	[thread overview]
Message-ID: <04992615-0914-48C0-BA3C-EA2DD175D8DF@ucsd.edu> (raw)
In-Reply-To: <CAFAhFSUS56h-DYR_PpBcvxF9n8OCpc8FdKAx7nxYnrEphrJw9w@mail.gmail.com>



> On Dec 18, 2019, at 9:10 AM, Lawrence Bottorff <borgauf@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?
> 

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

  reply	other threads:[~2019-12-18 18:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-18 17:10 Calling/using named babel code blocks Lawrence Bottorff
2019-12-18 18:03 ` Berry, Charles [this message]
2019-12-18 18:33 ` John Kitchin

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

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=04992615-0914-48C0-BA3C-EA2DD175D8DF@ucsd.edu \
    --to=ccberry@health.ucsd.edu \
    --cc=borgauf@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).