Re: appearance of list as results from evaluating code blocks

2021-06-26 Thread Tim Cross


John Kitchin  writes:

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

Yes, I think your probably correct.

If the form is wrapped in (clojure.pprint/pprint ), then the 'code'
result from evaluation would indeed be nil as the return value for
pprint is nil.

The ob-clojure module is IMO a little 'odd' because it uses cider, so
there is another layer of indirection you don't see with other ob-*
which just run the code inside a language shell. I also find this
distinction between 'code' and 'value' a bit confusing at times. I can
see why something is needed (for example, when running shell scripts and
sometimes you want the 'output' and sometimes you want the exit code
etc. However, the distinction is less clear in some languages, like
clojure, where there is no real distinction i.e. how does code differ
from value as a result? What does 'code' really mean in this context?.

I think the ob-clojure library probably needs a bit of work. Since it
was originally written, clojure has moved on a bit and it would probably
make sense to look at possibly basing it on clj-tools rather than cider.
When I was trying to use it, I constantly ran into problems because
cider was evolving too rapidly and things kept breaking. I actually had
better success using the 'inf-clojure' interface, but that had issues
too (for example, with the :session switch).

Someone did send in a patch some months back which had a first go at
implementing support for clj-tools. I was too busy to review it at the
time., I later went to have a look at it and a message was sent to the
patch author for a copy of the most recent version of the patch, but
there was no response. 
-- 
Tim Cross



Re: appearance of list as results from evaluating code blocks

2021-06-25 Thread John Kitchin
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
@johnkitchin
http://kitchingroup.cheme.cmu.edu



On Thu, Jun 24, 2021 at 1:47 PM Johannes Brauer 
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 :
>
> 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
> @johnkitchin
> http://kitchingroup.cheme.cmu.edu
>
>
>
> On Thu, Jun 24, 2021 at 10:31 AM Johannes Brauer 
> 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
>>
>>
>


Re: appearance of list as results from evaluating code blocks

2021-06-24 Thread Johannes Brauer
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 
mailto:jkitc...@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
@johnkitchin
http://kitchingroup.cheme.cmu.edu



On Thu, Jun 24, 2021 at 10:31 AM Johannes Brauer 
mailto:bra...@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




Re: appearance of list as results from evaluating code blocks

2021-06-24 Thread John Kitchin
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
@johnkitchin
http://kitchingroup.cheme.cmu.edu



On Thu, Jun 24, 2021 at 10:31 AM Johannes Brauer 
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
>
>


Re: appearance of list as results from evaluating code blocks

2021-06-24 Thread Johannes Brauer
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



Re: appearance of list as results from evaluating code blocks

2021-06-24 Thread Eric S Fraga
On Thursday, 24 Jun 2021 at 10:46, Johannes Brauer wrote:
>   #+begin_src clojure :results verbatim :wrap src clojure
> (list 1 2 (+ 1 2))
>   #+end_src

For completeness, another option is ":results verbatim drawer" without
:wrap.

-- 
: Eric S Fraga via Emacs 28.0.50, Org release_9.4.6-571-gc591be
: Latest paper written in org: https://arxiv.org/abs/2106.05096



Re: appearance of list as results from evaluating code blocks

2021-06-24 Thread Johannes Brauer
Hi Rodrigo!

Thanks a lot for the detailed information. In the meantime I’ve studied the 
org-mode manual a bit more closely (perhaps, I should have done that before 
asking my question …) and found the following interesting possibilitiy:

  #+begin_src clojure :results verbatim :wrap src clojure
(list 1 2 (+ 1 2))
  #+end_src

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

Johannes

> Am 23.06.2021 um 23:14 schrieb Rodrigo Morales :
> 
> Johannes Brauer  writes:
> 
> Johannes Brauer writes:
> 
>> thanks, that works
> 
> While that works, you might be interested in ":results verbatim" instead
> of ":results raw" since when using "verbatim" the results are replaced
> when re-evaluating the code block. See minimal working example below.
> 
> After pressing =C-c C-c= five times
> 
> #+BEGIN_SRC elisp :results raw
> (list 1 2 3)
> #+END_SRC
> 
> #+RESULTS:
> (1 2 3)
> (1 2 3)
> (1 2 3)
> (1 2 3)
> (1 2 3)
> 
> After pressing =C-c C-c= five times
> 
> #+BEGIN_SRC elisp :results verbatim
> (list 1 2 3)
> #+END_SRC
> 
> #+RESULTS:
> #+begin_example
> (1 2 3)
> #+end_example
> 
> PS: If you haven't customized Org Mode enough, you might get a ":" as
> the prefix of some of your results.
> 
> #+BEGIN_SRC elisp :results verbatim
> (list 1 2 3)
> #+END_SRC
> 
> #+RESULTS:
> : (1 2 3)
> 
> As can be seen above, the results are not enclosed within
> #+begin_example and #+end_example. To enable this, set the following.
> 
> #+BEGIN_SRC elisp
> (setq org-babel-min-lines-for-block-output 0)
> #+END_SRC
> 
> Once you set the option shown above, you might get the following when
> evaluating the code block.
> 
> #+BEGIN_SRC elisp :results verbatim
> (list 1 2 3)
> #+END_SRC
> 
> #+RESULTS:
> #+begin_example
> (1 2 3)
> #+end_example



Re: appearance of list as results from evaluating code blocks

2021-06-23 Thread George Mauer
What about :results code
The default is a elisp code block so you get syntax coloring

On Wed, Jun 23, 2021, 16:22 Rodrigo Morales 
wrote:

> Johannes Brauer  writes:
>
> Johannes Brauer writes:
>
> > thanks, that works
>
> While that works, you might be interested in ":results verbatim" instead
> of ":results raw" since when using "verbatim" the results are replaced
> when re-evaluating the code block. See minimal working example below.
>
> After pressing =C-c C-c= five times
>
> #+BEGIN_SRC elisp :results raw
> (list 1 2 3)
> #+END_SRC
>
> #+RESULTS:
> (1 2 3)
> (1 2 3)
> (1 2 3)
> (1 2 3)
> (1 2 3)
>
> After pressing =C-c C-c= five times
>
> #+BEGIN_SRC elisp :results verbatim
> (list 1 2 3)
> #+END_SRC
>
> #+RESULTS:
> #+begin_example
> (1 2 3)
> #+end_example
>
> PS: If you haven't customized Org Mode enough, you might get a ":" as
> the prefix of some of your results.
>
> #+BEGIN_SRC elisp :results verbatim
> (list 1 2 3)
> #+END_SRC
>
> #+RESULTS:
> : (1 2 3)
>
> As can be seen above, the results are not enclosed within
> #+begin_example and #+end_example. To enable this, set the following.
>
> #+BEGIN_SRC elisp
> (setq org-babel-min-lines-for-block-output 0)
> #+END_SRC
>
> Once you set the option shown above, you might get the following when
> evaluating the code block.
>
> #+BEGIN_SRC elisp :results verbatim
> (list 1 2 3)
> #+END_SRC
>
> #+RESULTS:
> #+begin_example
> (1 2 3)
> #+end_example
>
>


Re: appearance of list as results from evaluating code blocks

2021-06-23 Thread Rodrigo Morales
Johannes Brauer  writes:

Johannes Brauer writes:

> thanks, that works

While that works, you might be interested in ":results verbatim" instead
of ":results raw" since when using "verbatim" the results are replaced
when re-evaluating the code block. See minimal working example below.

After pressing =C-c C-c= five times

#+BEGIN_SRC elisp :results raw
(list 1 2 3)
#+END_SRC

#+RESULTS:
(1 2 3)
(1 2 3)
(1 2 3)
(1 2 3)
(1 2 3)

After pressing =C-c C-c= five times

#+BEGIN_SRC elisp :results verbatim
(list 1 2 3)
#+END_SRC

#+RESULTS:
#+begin_example
(1 2 3)
#+end_example

PS: If you haven't customized Org Mode enough, you might get a ":" as
the prefix of some of your results.

#+BEGIN_SRC elisp :results verbatim
(list 1 2 3)
#+END_SRC

#+RESULTS:
: (1 2 3)

As can be seen above, the results are not enclosed within
#+begin_example and #+end_example. To enable this, set the following.

#+BEGIN_SRC elisp
(setq org-babel-min-lines-for-block-output 0)
#+END_SRC

Once you set the option shown above, you might get the following when
evaluating the code block.

#+BEGIN_SRC elisp :results verbatim
(list 1 2 3)
#+END_SRC

#+RESULTS:
#+begin_example
(1 2 3)
#+end_example



Re: appearance of list as results from evaluating code blocks

2021-06-23 Thread Rodrigo Morales
Johannes Brauer  writes:

Johannes Brauer writes:

> thanks, that works

While that works, you might be interested in ":results verbatim" instead
of ":results raw" since when using "verbatim" the results are replaced
when re-evaluating the code block. See minimal working example below.

After pressing =C-c C-c= five times

#+BEGIN_SRC elisp :results raw
(list 1 2 3)
#+END_SRC

#+RESULTS:
(1 2 3)
(1 2 3)
(1 2 3)
(1 2 3)
(1 2 3)

After pressing =C-c C-c= five times

#+BEGIN_SRC elisp :results verbatim
(list 1 2 3)
#+END_SRC

#+RESULTS:
#+begin_example
(1 2 3)
#+end_example

PS: If you haven't customized Org Mode enough, you might get a ":" as
the prefix of some of your results.

#+BEGIN_SRC elisp :results verbatim
(list 1 2 3)
#+END_SRC

#+RESULTS:
: (1 2 3)

As can be seen above, the results are not enclosed within
#+begin_example and #+end_example. To enable this, set the following.

#+BEGIN_SRC elisp
(setq org-babel-min-lines-for-block-output 0)
#+END_SRC

Once you set the option shown above, you might get the following when
evaluating the code block.

#+BEGIN_SRC elisp :results verbatim
(list 1 2 3)
#+END_SRC

#+RESULTS:
#+begin_example
(1 2 3)
#+end_example



Re: appearance of list as results from evaluating code blocks

2021-06-23 Thread Johannes Brauer
Hi Juan Manuel,

thanks, that works

Best regards
Johannes

> Am 23.06.2021 um 21:43 schrieb Juan Manuel Macías :
> 
> Hi Johannes,
> 
> Johannes Brauer writes:
> 
>> Hi!
>> Evaluating a code block containing a list expression using org-babel for 
>> elisp or Clojure, for example
>> (list 1 2 3)
>> I get
>> #+RESULTS:
>>  | 1 | 2 | 3 |
>> I would prefer
>> #+RESULTS:
>>  ( 1  2  3 )
>> 
>> Is it possible to get this.
> 
> Try
> 
> #+begin_src emacs-lisp :results raw 
> (list 1 2 3)
> #+end_src
> 
> #+RESULTS:
> (1 2 3)
> 
> Best regards,
> 
> Juan Manuel 
> 



Re: appearance of list as results from evaluating code blocks

2021-06-23 Thread Juan Manuel Macías
Hi Johannes,

Johannes Brauer writes:

> Hi!
> Evaluating a code block containing a list expression using org-babel for 
> elisp or Clojure, for example
> (list 1 2 3)
> I get
>  #+RESULTS:
>   | 1 | 2 | 3 |
> I would prefer
>  #+RESULTS:
>   ( 1  2  3 )
>
> Is it possible to get this.

Try

#+begin_src emacs-lisp :results raw 
(list 1 2 3)
#+end_src

#+RESULTS:
(1 2 3)

Best regards,

Juan Manuel 




appearance of list as results from evaluating code blocks

2021-06-23 Thread Johannes Brauer
Hi!
Evaluating a code block containing a list expression using org-babel for elisp 
or Clojure, for example
(list 1 2 3)
I get
 #+RESULTS:
  | 1 | 2 | 3 |
I would prefer
 #+RESULTS:
  ( 1  2  3 )

Is it possible to get this.

I am using
Aquamacs 3.5nightly  GNU Emacs 25.3.50.1 (x86_64-apple-darwin19.6.0, NS 
appkit-1894.60 Version 10.15.7 (Build 19H2))
macOs 11.4
Org mode version 9.3.7

Johannes