From mboxrd@z Thu Jan 1 00:00:00 1970 From: Lawrence Bottorff Subject: Re: Generate new babel code blocks and/or initialized code/data? Date: Sat, 24 Sep 2016 17:02:49 -0400 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a113fb554aee0ad053d473729 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:55315) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bnu66-0000bz-9k for emacs-orgmode@gnu.org; Sat, 24 Sep 2016 17:02:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bnu63-0002Gu-Pg for emacs-orgmode@gnu.org; Sat, 24 Sep 2016 17:02:57 -0400 Received: from mail-io0-x235.google.com ([2607:f8b0:4001:c06::235]:36399) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bnu63-0002Gm-Ia for emacs-orgmode@gnu.org; Sat, 24 Sep 2016 17:02:55 -0400 Received: by mail-io0-x235.google.com with SMTP id m79so149793584ioo.3 for ; Sat, 24 Sep 2016 14:02:55 -0700 (PDT) In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: "Thomas S. Dye" Cc: emacs-orgmode Mailinglist --001a113fb554aee0ad053d473729 Content-Type: text/plain; charset=UTF-8 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 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 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 >> > > --001a113fb554aee0ad053d473729 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Sorry, mis-typed:

#+begin_sr= c clojure :var i=3Dmyfun1
(map inc i)
#+end_src

On Sat, Sep 2= 4, 2016 at 4:53 PM, Lawrence Bottorff <borgauf@gmail.com> wr= ote:
Not sure if you kno= w Clojure, but here's what I've been toying with:

#+name: my-test
#+begin_src clojure :var i=3D[1 2]
(map inc i)
#+end_src

#+RESULTS: my-t= est
| 2 | 3 |

looks good, but then=

#+name: myfun1
#+begin_src clojure= =C2=A0
(defn myfun1
=C2=A0 [ ]
=C2=A0 [8 9])<= /div>
#+end_src

#+begin_src clojure= :var i=3Dmyfunc1
(map inc i)
#+end_src

doesn't do anything, i.e., it doesn't process the m= yfunc1 and provide the vector [8 9]

This elisp cod= e works, though:

#+name: mylist1
#+= begin_src emacs-lisp=C2=A0
(defun mylist1 ()
=C2=A0 (li= st 1 2 3 4))
#+end_src

then
<= div>
#+begin_src emacs-lisp :var myx=3D(mylist1)
(mapcar '1+ myx)
#+end_src

#+RESU= LTS:
| 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), my= fun1, and myfun1() gives an error.



On Tue, Sep 20, 2016 at 3:33 PM, Thomas S. Dye <tsd@ts= dye.com> wrote:
Aloha Lawre= nce,

Lawrence Bottorff writes:

> So I can run code for a REPL-type language like Clojure in a babel cod= e
> 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=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 | :size |=C2= =A0 3 |
> | :name | left-eye=C2=A0 =C2=A0 =C2=A0 =C2=A0 | :size |=C2=A0 1 |
> | :name | right-eye=C2=A0 =C2=A0 =C2=A0 =C2=A0| :size |=C2=A0 1 |
> | :name | left-ear=C2=A0 =C2=A0 =C2=A0 =C2=A0 | :size |=C2=A0 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#orgheadl= ine13

You can pass the function results to a variable argument, which makes
possible chaining (see http://www.jstatsoft.org/v46/i03):
#+header: :var x=3Dmyfunc(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


--001a113fb554aee0ad053d473729--