emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: appearance of list as results from evaluating code blocks


From: John Kitchin
Subject: Re: appearance of list as results from evaluating code blocks
Date: Fri, 25 Jun 2021 12:16:20 -0400

I think something is fishy in ob-clojure.

When I look at how it runs, it is not obvious it is returning anything. Instead it is wrapping the body like this

"(clojure.pprint/pprint (do (list 1 2 (+ 1 2))))"

which I assume is going to stdout maybe? 

With Cider I eventually got to this intermediate result, which looks like maybe there is a terminating nil getting read from the repl that is eventually chomped to "".

Result: (dict "status" ("done" "state") "id" "12" "out" "(1 2 3)\nnil\n" "session" "c72a3a11-8982-4ead-a0bf-cb92a24a966c" "ns" "user" "value" "nil" "changed-namespaces" (dict) "repl-type" "clj")

That is my best guess for why you don't see the output. This happens in the function ob-clojure-eval-with-cider.
John

-----------------------------------
Professor John Kitchin (he/him/his)
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803


On Thu, Jun 24, 2021 at 1:47 PM Johannes Brauer <brauer@nordakademie.de> wrote:
Hi John!

There is no „return“ in Lisp languages. The return value of (list 1 2 3) is (1 2 3). Clojure is a Lisp language similar to Elisp. So 

#+begin_src clojure :results code
(list 1 2 (+ 1 2))
  #+end_src

should work for Clojure as it does für Elisp.

Johannes

Am 24.06.2021 um 18:28 schrieb John Kitchin <jkitchin@andrew.cmu.edu>:

That probably means the clojure block is returning nil as the value. I don't know what it means to return something in clojure, but here is what you have to do with Python, for example.

#+BEGIN_SRC python :results value code
[1, 2, 3]
#+END_SRC

#+RESULTS:
#+begin_src python
None
#+end_src

You have to explicitly return a value to see it.

#+BEGIN_SRC python :results value code
return [1, 2, 3]
#+END_SRC

#+RESULTS:
#+begin_src python
[1, 2, 3]
#+end_src


John

-----------------------------------
Professor John Kitchin (he/him/his)
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803


On Thu, Jun 24, 2021 at 10:31 AM Johannes Brauer <brauer@nordakademie.de> wrote:
What about :results code
The default is a elisp code block so you get syntax coloring

That works fore lisp:

  #+begin_src elisp :results code
(list 1 2 (+ 1 2))
  #+end_src

  #+RESULTS:
  #+begin_src elisp
  (1 2 3)
  #+end_src

But with Clojure I get

  #+begin_src clojure :results code
(list 1 2 (+ 1 2))
  #+end_src

  #+RESULTS:
  #+begin_src clojure
  nil
  #+end_src



reply via email to

[Prev in Thread] Current Thread [Next in Thread]