emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Calling/using named babel code blocks
@ 2019-12-18 17:10 Lawrence Bottorff
  2019-12-18 18:03 ` Berry, Charles
  2019-12-18 18:33 ` John Kitchin
  0 siblings, 2 replies; 3+ messages in thread
From: Lawrence Bottorff @ 2019-12-18 17:10 UTC (permalink / raw)
  To: emacs-orgmode Mailinglist

[-- Attachment #1: Type: text/plain, Size: 748 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 1367 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Calling/using named babel code blocks
  2019-12-18 17:10 Calling/using named babel code blocks Lawrence Bottorff
@ 2019-12-18 18:03 ` Berry, Charles
  2019-12-18 18:33 ` John Kitchin
  1 sibling, 0 replies; 3+ messages in thread
From: Berry, Charles @ 2019-12-18 18:03 UTC (permalink / raw)
  To: Lawrence Bottorff; +Cc: emacs-orgmode Mailinglist



> 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Calling/using named babel code blocks
  2019-12-18 17:10 Calling/using named babel code blocks Lawrence Bottorff
  2019-12-18 18:03 ` Berry, Charles
@ 2019-12-18 18:33 ` John Kitchin
  1 sibling, 0 replies; 3+ messages in thread
From: John Kitchin @ 2019-12-18 18:33 UTC (permalink / raw)
  To: Lawrence Bottorff; +Cc: emacs-orgmode Mailinglist

[-- Attachment #1: Type: text/plain, Size: 1492 bytes --]

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 <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?
>
> LB
>
>
>

[-- Attachment #2: Type: text/html, Size: 2718 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-12-18 18:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-12-18 17:10 Calling/using named babel code blocks Lawrence Bottorff
2019-12-18 18:03 ` Berry, Charles
2019-12-18 18:33 ` John Kitchin

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).