* Generate new babel code blocks and/or initialized code/data?
@ 2016-09-20 19:07 Lawrence Bottorff
2016-09-20 19:33 ` Thomas S. Dye
0 siblings, 1 reply; 7+ messages in thread
From: Lawrence Bottorff @ 2016-09-20 19:07 UTC (permalink / raw)
To: emacs-orgmode Mailinglist
[-- Attachment #1: Type: text/plain, Size: 789 bytes --]
So I can run code for a REPL-type language like Clojure in a babel code
block and get "results," e.g., a Clojure code block takes in a vector of
mappings and produces new "results":
#+RESULTS[abc5c51bb569a82c19c4eea1c385c74e839922c7]:
symmetrize-body-parts-test
| :name | head | :size | 3 |
| :name | left-eye | :size | 1 |
| :name | right-eye | :size | 1 |
| :name | left-ear | :size | 1 |
. . .
but could I generate results that aren't just static output listed after a
#+RESULTS tag, rather, embedded in a newly created babel code block? I'd
like such output "initialized" as far as the running REPL is concerned too.
Is it possible to generate new code/data that is immediately known to the
REPL session? Any examples don't have to be Clojure.
LB
[-- Attachment #2: Type: text/html, Size: 1037 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Generate new babel code blocks and/or initialized code/data?
2016-09-20 19:07 Generate new babel code blocks and/or initialized code/data? Lawrence Bottorff
@ 2016-09-20 19:33 ` Thomas S. Dye
2016-09-24 20:53 ` Lawrence Bottorff
0 siblings, 1 reply; 7+ messages in thread
From: Thomas S. Dye @ 2016-09-20 19:33 UTC (permalink / raw)
To: Lawrence Bottorff; +Cc: emacs-orgmode Mailinglist
Aloha Lawrence,
Lawrence Bottorff writes:
> So I can run code for a REPL-type language like Clojure in a babel code
> block and get "results," e.g., a Clojure code block takes in a vector of
> mappings and produces new "results":
>
> #+RESULTS[abc5c51bb569a82c19c4eea1c385c74e839922c7]:
> symmetrize-body-parts-test
> | :name | head | :size | 3 |
> | :name | left-eye | :size | 1 |
> | :name | right-eye | :size | 1 |
> | :name | left-ear | :size | 1 |
> . . .
>
> but could I generate results that aren't just static output listed after a
> #+RESULTS tag, rather, embedded in a newly created babel code block? I'd
> like such output "initialized" as far as the running REPL is concerned too.
> Is it possible to generate new code/data that is immediately known to the
> REPL session? Any examples don't have to be Clojure.
You can use the :session header argument which will give you access to
any variables created during the session:
http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-clojure.html#orgheadline13
You can pass the function results to a variable argument, which makes
possible chaining (see http://www.jstatsoft.org/v46/i03):
#+header: :var x=myfunc(2)
You can also embed and call a function in a source code block using noweb
syntax:
http://orgmode.org/worg/org-contrib/babel/intro.html#literate-programming
hth,
Tom
--
Thomas S. Dye
http://www.tsdye.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Generate new babel code blocks and/or initialized code/data?
2016-09-20 19:33 ` Thomas S. Dye
@ 2016-09-24 20:53 ` Lawrence Bottorff
2016-09-24 21:02 ` Lawrence Bottorff
2016-09-25 0:03 ` Thomas S. Dye
0 siblings, 2 replies; 7+ messages in thread
From: Lawrence Bottorff @ 2016-09-24 20:53 UTC (permalink / raw)
To: Thomas S. Dye; +Cc: emacs-orgmode Mailinglist
[-- Attachment #1: Type: text/plain, Size: 2561 bytes --]
Not sure if you know Clojure, but here's what I've been toying with:
#+name: my-test
#+begin_src clojure :var i=[1 2]
(map inc i)
#+end_src
#+RESULTS: my-test
| 2 | 3 |
looks good, but then
#+name: myfun1
#+begin_src clojure
(defn myfun1
[ ]
[8 9])
#+end_src
#+begin_src clojure :var i=myfunc1
(map inc i)
#+end_src
doesn't do anything, i.e., it doesn't process the myfunc1 and provide the
vector [8 9]
This elisp code works, though:
#+name: mylist1
#+begin_src emacs-lisp
(defun mylist1 ()
(list 1 2 3 4))
#+end_src
then
#+begin_src emacs-lisp :var myx=(mylist1)
(mapcar '1+ myx)
#+end_src
#+RESULTS:
| 2 | 3 | 4 | 5 |
Note how I put mylist1 in parens. Without produced odd output
#+RESULTS:
| 110 | 122 | 109 | 106 | 116 | 117 | 50 |
. . . which is literally taking the ascii letters of the word "mylist1" and
incrementing them. (Too much fun. . . ). What might be wrong with my
Clojure attempt? I've tried (myfun1), myfun1, and myfun1() gives an error.
On Tue, Sep 20, 2016 at 3:33 PM, Thomas S. Dye <tsd@tsdye.com> wrote:
> Aloha Lawrence,
>
> Lawrence Bottorff writes:
>
> > So I can run code for a REPL-type language like Clojure in a babel code
> > block and get "results," e.g., a Clojure code block takes in a vector of
> > mappings and produces new "results":
> >
> > #+RESULTS[abc5c51bb569a82c19c4eea1c385c74e839922c7]:
> > symmetrize-body-parts-test
> > | :name | head | :size | 3 |
> > | :name | left-eye | :size | 1 |
> > | :name | right-eye | :size | 1 |
> > | :name | left-ear | :size | 1 |
> > . . .
> >
> > but could I generate results that aren't just static output listed after
> a
> > #+RESULTS tag, rather, embedded in a newly created babel code block? I'd
> > like such output "initialized" as far as the running REPL is concerned
> too.
> > Is it possible to generate new code/data that is immediately known to the
> > REPL session? Any examples don't have to be Clojure.
>
> You can use the :session header argument which will give you access to
> any variables created during the session:
>
> http://orgmode.org/worg/org-contrib/babel/languages/ob-
> doc-clojure.html#orgheadline13
>
> You can pass the function results to a variable argument, which makes
> possible chaining (see http://www.jstatsoft.org/v46/i03):
>
> #+header: :var x=myfunc(2)
>
> You can also embed and call a function in a source code block using noweb
> syntax:
>
> http://orgmode.org/worg/org-contrib/babel/intro.html#literate-programming
>
> hth,
> Tom
>
> --
> Thomas S. Dye
> http://www.tsdye.com
>
[-- Attachment #2: Type: text/html, Size: 4271 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Generate new babel code blocks and/or initialized code/data?
2016-09-24 20:53 ` Lawrence Bottorff
@ 2016-09-24 21:02 ` Lawrence Bottorff
2016-09-25 0:03 ` Thomas S. Dye
1 sibling, 0 replies; 7+ messages in thread
From: Lawrence Bottorff @ 2016-09-24 21:02 UTC (permalink / raw)
To: Thomas S. Dye; +Cc: emacs-orgmode Mailinglist
[-- Attachment #1: Type: text/plain, Size: 2864 bytes --]
Sorry, mis-typed:
#+begin_src clojure :var i=myfun1
(map inc i)
#+end_src
On Sat, Sep 24, 2016 at 4:53 PM, Lawrence Bottorff <borgauf@gmail.com>
wrote:
> Not sure if you know Clojure, but here's what I've been toying with:
>
> #+name: my-test
> #+begin_src clojure :var i=[1 2]
> (map inc i)
> #+end_src
>
> #+RESULTS: my-test
> | 2 | 3 |
>
> looks good, but then
>
> #+name: myfun1
> #+begin_src clojure
> (defn myfun1
> [ ]
> [8 9])
> #+end_src
>
> #+begin_src clojure :var i=myfunc1
> (map inc i)
> #+end_src
>
> doesn't do anything, i.e., it doesn't process the myfunc1 and provide the
> vector [8 9]
>
> This elisp code works, though:
>
> #+name: mylist1
> #+begin_src emacs-lisp
> (defun mylist1 ()
> (list 1 2 3 4))
> #+end_src
>
> then
>
> #+begin_src emacs-lisp :var myx=(mylist1)
> (mapcar '1+ myx)
> #+end_src
>
> #+RESULTS:
> | 2 | 3 | 4 | 5 |
>
> Note how I put mylist1 in parens. Without produced odd output
>
> #+RESULTS:
> | 110 | 122 | 109 | 106 | 116 | 117 | 50 |
>
> . . . which is literally taking the ascii letters of the word "mylist1"
> and incrementing them. (Too much fun. . . ). What might be wrong with my
> Clojure attempt? I've tried (myfun1), myfun1, and myfun1() gives an error.
>
>
>
> On Tue, Sep 20, 2016 at 3:33 PM, Thomas S. Dye <tsd@tsdye.com> wrote:
>
>> Aloha Lawrence,
>>
>> Lawrence Bottorff writes:
>>
>> > So I can run code for a REPL-type language like Clojure in a babel code
>> > block and get "results," e.g., a Clojure code block takes in a vector of
>> > mappings and produces new "results":
>> >
>> > #+RESULTS[abc5c51bb569a82c19c4eea1c385c74e839922c7]:
>> > symmetrize-body-parts-test
>> > | :name | head | :size | 3 |
>> > | :name | left-eye | :size | 1 |
>> > | :name | right-eye | :size | 1 |
>> > | :name | left-ear | :size | 1 |
>> > . . .
>> >
>> > but could I generate results that aren't just static output listed
>> after a
>> > #+RESULTS tag, rather, embedded in a newly created babel code block? I'd
>> > like such output "initialized" as far as the running REPL is concerned
>> too.
>> > Is it possible to generate new code/data that is immediately known to
>> the
>> > REPL session? Any examples don't have to be Clojure.
>>
>> You can use the :session header argument which will give you access to
>> any variables created during the session:
>>
>> http://orgmode.org/worg/org-contrib/babel/languages/ob-doc-
>> clojure.html#orgheadline13
>>
>> You can pass the function results to a variable argument, which makes
>> possible chaining (see http://www.jstatsoft.org/v46/i03):
>>
>> #+header: :var x=myfunc(2)
>>
>> You can also embed and call a function in a source code block using noweb
>> syntax:
>>
>> http://orgmode.org/worg/org-contrib/babel/intro.html#literate-programming
>>
>> hth,
>> Tom
>>
>> --
>> Thomas S. Dye
>> http://www.tsdye.com
>>
>
>
[-- Attachment #2: Type: text/html, Size: 4792 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Generate new babel code blocks and/or initialized code/data?
2016-09-24 20:53 ` Lawrence Bottorff
2016-09-24 21:02 ` Lawrence Bottorff
@ 2016-09-25 0:03 ` Thomas S. Dye
2016-09-25 1:49 ` Lawrence Bottorff
1 sibling, 1 reply; 7+ messages in thread
From: Thomas S. Dye @ 2016-09-25 0:03 UTC (permalink / raw)
To: Lawrence Bottorff; +Cc: emacs-orgmode Mailinglist
Aloha Lawrence,
I don't know the Clojure dialect, but I think the problem is that the
myfun1 source code block returns a function. It doesn't evaluate
the function and return a result, which is I think what you are
expecting.
You can use noweb expansion of myfun1 to define the function inside
another source code block, then use the function in the normal way in
the source code block (or in the session, if you have that set).
Or, you might change the myfun1 source code block to return a list,
rather than a function (if I'm reading Clojure correctly):
#+name: myfun1
#+begin_source clojure
[8 9]
#+end_source
hth,
Tom
Lawrence Bottorff writes:
> Not sure if you know Clojure, but here's what I've been toying with:
>
> #+name: my-test
> #+begin_src clojure :var i=[1 2]
> (map inc i)
> #+end_src
>
> #+RESULTS: my-test
> | 2 | 3 |
>
> looks good, but then
>
> #+name: myfun1
> #+begin_src clojure
> (defn myfun1
> [ ]
> [8 9])
> #+end_src
>
> #+begin_src clojure :var i=myfunc1
> (map inc i)
> #+end_src
>
> doesn't do anything, i.e., it doesn't process the myfunc1 and provide the
> vector [8 9]
>
> This elisp code works, though:
>
> #+name: mylist1
> #+begin_src emacs-lisp
> (defun mylist1 ()
> (list 1 2 3 4))
> #+end_src
>
> then
>
> #+begin_src emacs-lisp :var myx=(mylist1)
> (mapcar '1+ myx)
> #+end_src
>
> #+RESULTS:
> | 2 | 3 | 4 | 5 |
>
> Note how I put mylist1 in parens. Without produced odd output
>
> #+RESULTS:
> | 110 | 122 | 109 | 106 | 116 | 117 | 50 |
>
> . . . which is literally taking the ascii letters of the word "mylist1" and
> incrementing them. (Too much fun. . . ). What might be wrong with my
> Clojure attempt? I've tried (myfun1), myfun1, and myfun1() gives an error.
>
>
>
> On Tue, Sep 20, 2016 at 3:33 PM, Thomas S. Dye <tsd@tsdye.com> wrote:
>
>> Aloha Lawrence,
>>
>> Lawrence Bottorff writes:
>>
>> > So I can run code for a REPL-type language like Clojure in a babel code
>> > block and get "results," e.g., a Clojure code block takes in a vector of
>> > mappings and produces new "results":
>> >
>> > #+RESULTS[abc5c51bb569a82c19c4eea1c385c74e839922c7]:
>> > symmetrize-body-parts-test
>> > | :name | head | :size | 3 |
>> > | :name | left-eye | :size | 1 |
>> > | :name | right-eye | :size | 1 |
>> > | :name | left-ear | :size | 1 |
>> > . . .
>> >
>> > but could I generate results that aren't just static output listed after
>> a
>> > #+RESULTS tag, rather, embedded in a newly created babel code block? I'd
>> > like such output "initialized" as far as the running REPL is concerned
>> too.
>> > Is it possible to generate new code/data that is immediately known to the
>> > REPL session? Any examples don't have to be Clojure.
>>
>> You can use the :session header argument which will give you access to
>> any variables created during the session:
>>
>> http://orgmode.org/worg/org-contrib/babel/languages/ob-
>> doc-clojure.html#orgheadline13
>>
>> You can pass the function results to a variable argument, which makes
>> possible chaining (see http://www.jstatsoft.org/v46/i03):
>>
>> #+header: :var x=myfunc(2)
>>
>> You can also embed and call a function in a source code block using noweb
>> syntax:
>>
>> http://orgmode.org/worg/org-contrib/babel/intro.html#literate-programming
>>
>> hth,
>> Tom
>>
>> --
>> Thomas S. Dye
>> http://www.tsdye.com
>>
--
Thomas S. Dye
http://www.tsdye.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Generate new babel code blocks and/or initialized code/data?
2016-09-25 0:03 ` Thomas S. Dye
@ 2016-09-25 1:49 ` Lawrence Bottorff
2016-09-25 3:10 ` Thomas S. Dye
0 siblings, 1 reply; 7+ messages in thread
From: Lawrence Bottorff @ 2016-09-25 1:49 UTC (permalink / raw)
To: Thomas S. Dye; +Cc: emacs-orgmode Mailinglist
[-- Attachment #1: Type: text/plain, Size: 5176 bytes --]
If I evaluate this:
#+name: myfun1
#+begin_src clojure
(defn myfun1
[ ]
9)
#+end_src
#+RESULTS: myfun1
: #'clojure-noob.core/myfun1
then this
#+begin_src clojure
(inc (myfun1))
#+end_src
#+RESULTS:
: 10
I've got the right answer, but I've totally bypassed the :var
functionality. In my elisp example
#+begin_src emacs-lisp :var myx=(mylist1)
(mapcar '1+ myx)
#+end_src
#+RESULTS:
| 2 | 3 | 4 | 5 |
it seems to be as you say, i.e., the function needs to be evaluated, and,
yes, the mylist1 function in parens does the trick. But this
#+begin_src clojure :var i=(myfun1)
(inc i)
#+end_src
produces this in *Messages*:
eval: Symbol’s function definition is void: myfun1
However, this
#+name: myfun1-test2
#+begin_src clojure
(myfun1)
#+end_src
#+RESULTS: myfun1-test2
: 9
does finally get seen and evaluated:
#+begin_src clojure :var i=myfun1-test2
(inc i)
#+end_src
#+RESULTS:
: 10
But this adds an extra step just to use :var. I'm guessing regular Lisp and
maybe Scheme (geiser) know about var i=(myfun1), . Will test, but I've got
to swap out my .emacs.d first. As far as noweb is concerned, doing
<<myfun1>> doesn't win me anything, does it? It's the same as (myfun1)
above.
On Sat, Sep 24, 2016 at 8:03 PM, Thomas S. Dye <tsd@tsdye.com> wrote:
> Aloha Lawrence,
>
> I don't know the Clojure dialect, but I think the problem is that the
> myfun1 source code block returns a function. It doesn't evaluate
> the function and return a result, which is I think what you are
> expecting.
>
> You can use noweb expansion of myfun1 to define the function inside
> another source code block, then use the function in the normal way in
> the source code block (or in the session, if you have that set).
>
> Or, you might change the myfun1 source code block to return a list,
> rather than a function (if I'm reading Clojure correctly):
>
> #+name: myfun1
> #+begin_source clojure
> [8 9]
> #+end_source
>
> hth,
> Tom
>
> Lawrence Bottorff writes:
>
> > Not sure if you know Clojure, but here's what I've been toying with:
> >
> > #+name: my-test
> > #+begin_src clojure :var i=[1 2]
> > (map inc i)
> > #+end_src
> >
> > #+RESULTS: my-test
> > | 2 | 3 |
> >
> > looks good, but then
> >
> > #+name: myfun1
> > #+begin_src clojure
> > (defn myfun1
> > [ ]
> > [8 9])
> > #+end_src
> >
> > #+begin_src clojure :var i=myfunc1
> > (map inc i)
> > #+end_src
> >
> > doesn't do anything, i.e., it doesn't process the myfunc1 and provide the
> > vector [8 9]
> >
> > This elisp code works, though:
> >
> > #+name: mylist1
> > #+begin_src emacs-lisp
> > (defun mylist1 ()
> > (list 1 2 3 4))
> > #+end_src
> >
> > then
> >
> > #+begin_src emacs-lisp :var myx=(mylist1)
> > (mapcar '1+ myx)
> > #+end_src
> >
> > #+RESULTS:
> > | 2 | 3 | 4 | 5 |
> >
> > Note how I put mylist1 in parens. Without produced odd output
> >
> > #+RESULTS:
> > | 110 | 122 | 109 | 106 | 116 | 117 | 50 |
> >
> > . . . which is literally taking the ascii letters of the word "mylist1"
> and
> > incrementing them. (Too much fun. . . ). What might be wrong with my
> > Clojure attempt? I've tried (myfun1), myfun1, and myfun1() gives an
> error.
> >
> >
> >
> > On Tue, Sep 20, 2016 at 3:33 PM, Thomas S. Dye <tsd@tsdye.com> wrote:
> >
> >> Aloha Lawrence,
> >>
> >> Lawrence Bottorff writes:
> >>
> >> > So I can run code for a REPL-type language like Clojure in a babel
> code
> >> > block and get "results," e.g., a Clojure code block takes in a vector
> of
> >> > mappings and produces new "results":
> >> >
> >> > #+RESULTS[abc5c51bb569a82c19c4eea1c385c74e839922c7]:
> >> > symmetrize-body-parts-test
> >> > | :name | head | :size | 3 |
> >> > | :name | left-eye | :size | 1 |
> >> > | :name | right-eye | :size | 1 |
> >> > | :name | left-ear | :size | 1 |
> >> > . . .
> >> >
> >> > but could I generate results that aren't just static output listed
> after
> >> a
> >> > #+RESULTS tag, rather, embedded in a newly created babel code block?
> I'd
> >> > like such output "initialized" as far as the running REPL is concerned
> >> too.
> >> > Is it possible to generate new code/data that is immediately known to
> the
> >> > REPL session? Any examples don't have to be Clojure.
> >>
> >> You can use the :session header argument which will give you access to
> >> any variables created during the session:
> >>
> >> http://orgmode.org/worg/org-contrib/babel/languages/ob-
> >> doc-clojure.html#orgheadline13
> >>
> >> You can pass the function results to a variable argument, which makes
> >> possible chaining (see http://www.jstatsoft.org/v46/i03):
> >>
> >> #+header: :var x=myfunc(2)
> >>
> >> You can also embed and call a function in a source code block using
> noweb
> >> syntax:
> >>
> >> http://orgmode.org/worg/org-contrib/babel/intro.html#
> literate-programming
> >>
> >> hth,
> >> Tom
> >>
> >> --
> >> Thomas S. Dye
> >> http://www.tsdye.com
> >>
>
>
> --
> Thomas S. Dye
> http://www.tsdye.com
>
[-- Attachment #2: Type: text/html, Size: 7740 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Generate new babel code blocks and/or initialized code/data?
2016-09-25 1:49 ` Lawrence Bottorff
@ 2016-09-25 3:10 ` Thomas S. Dye
0 siblings, 0 replies; 7+ messages in thread
From: Thomas S. Dye @ 2016-09-25 3:10 UTC (permalink / raw)
To: Lawrence Bottorff; +Cc: emacs-orgmode Mailinglist
Aloha Lawrence,
Here
#+begin_src clojure :var i=(myfun1)
(inc i)
#+end_src
you are asking emacs-lisp to evaluate myfun1, which is not an emacs-lisp
function.
See http://orgmode.org/manual/var.html#var, "Emacs Lisp evaluation of
variables"
I'm not sure why you are able to bypass the :var functionality in
clojure. What you are seeing is the behavior I expect in a :session.
I'm not a programmer--you'll need some input from a programmer on the
list to sort this one out.
hth,
Tom
Lawrence Bottorff writes:
> If I evaluate this:
>
> #+name: myfun1
> #+begin_src clojure
> (defn myfun1
> [ ]
> 9)
> #+end_src
>
> #+RESULTS: myfun1
> : #'clojure-noob.core/myfun1
>
> then this
>
> #+begin_src clojure
> (inc (myfun1))
> #+end_src
>
> #+RESULTS:
> : 10
>
> I've got the right answer, but I've totally bypassed the :var
> functionality. In my elisp example
>
> #+begin_src emacs-lisp :var myx=(mylist1)
> (mapcar '1+ myx)
> #+end_src
>
> #+RESULTS:
> | 2 | 3 | 4 | 5 |
>
> it seems to be as you say, i.e., the function needs to be evaluated, and,
> yes, the mylist1 function in parens does the trick. But this
>
> #+begin_src clojure :var i=(myfun1)
> (inc i)
> #+end_src
>
> produces this in *Messages*:
>
> eval: Symbol’s function definition is void: myfun1
>
> However, this
>
> #+name: myfun1-test2
> #+begin_src clojure
> (myfun1)
> #+end_src
>
> #+RESULTS: myfun1-test2
> : 9
>
> does finally get seen and evaluated:
>
> #+begin_src clojure :var i=myfun1-test2
> (inc i)
> #+end_src
>
> #+RESULTS:
> : 10
>
> But this adds an extra step just to use :var. I'm guessing regular Lisp and
> maybe Scheme (geiser) know about var i=(myfun1), . Will test, but I've got
> to swap out my .emacs.d first. As far as noweb is concerned, doing
> <<myfun1>> doesn't win me anything, does it? It's the same as (myfun1)
> above.
>
>
>
>
>
>
>
>
>
>
> On Sat, Sep 24, 2016 at 8:03 PM, Thomas S. Dye <tsd@tsdye.com> wrote:
>
>> Aloha Lawrence,
>>
>> I don't know the Clojure dialect, but I think the problem is that the
>> myfun1 source code block returns a function. It doesn't evaluate
>> the function and return a result, which is I think what you are
>> expecting.
>>
>> You can use noweb expansion of myfun1 to define the function inside
>> another source code block, then use the function in the normal way in
>> the source code block (or in the session, if you have that set).
>>
>> Or, you might change the myfun1 source code block to return a list,
>> rather than a function (if I'm reading Clojure correctly):
>>
>> #+name: myfun1
>> #+begin_source clojure
>> [8 9]
>> #+end_source
>>
>> hth,
>> Tom
>>
>> Lawrence Bottorff writes:
>>
>> > Not sure if you know Clojure, but here's what I've been toying with:
>> >
>> > #+name: my-test
>> > #+begin_src clojure :var i=[1 2]
>> > (map inc i)
>> > #+end_src
>> >
>> > #+RESULTS: my-test
>> > | 2 | 3 |
>> >
>> > looks good, but then
>> >
>> > #+name: myfun1
>> > #+begin_src clojure
>> > (defn myfun1
>> > [ ]
>> > [8 9])
>> > #+end_src
>> >
>> > #+begin_src clojure :var i=myfunc1
>> > (map inc i)
>> > #+end_src
>> >
>> > doesn't do anything, i.e., it doesn't process the myfunc1 and provide the
>> > vector [8 9]
>> >
>> > This elisp code works, though:
>> >
>> > #+name: mylist1
>> > #+begin_src emacs-lisp
>> > (defun mylist1 ()
>> > (list 1 2 3 4))
>> > #+end_src
>> >
>> > then
>> >
>> > #+begin_src emacs-lisp :var myx=(mylist1)
>> > (mapcar '1+ myx)
>> > #+end_src
>> >
>> > #+RESULTS:
>> > | 2 | 3 | 4 | 5 |
>> >
>> > Note how I put mylist1 in parens. Without produced odd output
>> >
>> > #+RESULTS:
>> > | 110 | 122 | 109 | 106 | 116 | 117 | 50 |
>> >
>> > . . . which is literally taking the ascii letters of the word "mylist1"
>> and
>> > incrementing them. (Too much fun. . . ). What might be wrong with my
>> > Clojure attempt? I've tried (myfun1), myfun1, and myfun1() gives an
>> error.
>> >
>> >
>> >
>> > On Tue, Sep 20, 2016 at 3:33 PM, Thomas S. Dye <tsd@tsdye.com> wrote:
>> >
>> >> Aloha Lawrence,
>> >>
>> >> Lawrence Bottorff writes:
>> >>
>> >> > So I can run code for a REPL-type language like Clojure in a babel
>> code
>> >> > block and get "results," e.g., a Clojure code block takes in a vector
>> of
>> >> > mappings and produces new "results":
>> >> >
>> >> > #+RESULTS[abc5c51bb569a82c19c4eea1c385c74e839922c7]:
>> >> > symmetrize-body-parts-test
>> >> > | :name | head | :size | 3 |
>> >> > | :name | left-eye | :size | 1 |
>> >> > | :name | right-eye | :size | 1 |
>> >> > | :name | left-ear | :size | 1 |
>> >> > . . .
>> >> >
>> >> > but could I generate results that aren't just static output listed
>> after
>> >> a
>> >> > #+RESULTS tag, rather, embedded in a newly created babel code block?
>> I'd
>> >> > like such output "initialized" as far as the running REPL is concerned
>> >> too.
>> >> > Is it possible to generate new code/data that is immediately known to
>> the
>> >> > REPL session? Any examples don't have to be Clojure.
>> >>
>> >> You can use the :session header argument which will give you access to
>> >> any variables created during the session:
>> >>
>> >> http://orgmode.org/worg/org-contrib/babel/languages/ob-
>> >> doc-clojure.html#orgheadline13
>> >>
>> >> You can pass the function results to a variable argument, which makes
>> >> possible chaining (see http://www.jstatsoft.org/v46/i03):
>> >>
>> >> #+header: :var x=myfunc(2)
>> >>
>> >> You can also embed and call a function in a source code block using
>> noweb
>> >> syntax:
>> >>
>> >> http://orgmode.org/worg/org-contrib/babel/intro.html#
>> literate-programming
>> >>
>> >> hth,
>> >> Tom
>> >>
>> >> --
>> >> Thomas S. Dye
>> >> http://www.tsdye.com
>> >>
>>
>>
>> --
>> Thomas S. Dye
>> http://www.tsdye.com
>>
--
Thomas S. Dye
http://www.tsdye.com
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2016-09-25 3:21 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-20 19:07 Generate new babel code blocks and/or initialized code/data? Lawrence Bottorff
2016-09-20 19:33 ` Thomas S. Dye
2016-09-24 20:53 ` Lawrence Bottorff
2016-09-24 21:02 ` Lawrence Bottorff
2016-09-25 0:03 ` Thomas S. Dye
2016-09-25 1:49 ` Lawrence Bottorff
2016-09-25 3:10 ` Thomas S. Dye
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.