Re: [O] ob-clojure: ':results pp' parses the output as a string value

2014-04-14 Thread Phill Wolf
Yes, perfect!


On Mon, Apr 14, 2014 at 6:35 AM, Oleh ohwoeo...@gmail.com wrote:

 Hi Phil,

 Could you test my last commit? Your case should be working now.

 regards,
 Oleh



[O] ob-clojure: ':results pp' parses the output as a string value

2014-04-13 Thread Phill Wolf
I am getting a strange effect from :results pp and ob-clojure.  It\n
looks\n like\n this.\n  I built Emacs 24.4.50 from trunk and cloned
ob-clojure from git today. clojure-mode is 20140331 from ELPA.  cider is
20140411 from ELPA.

Two examples follow.

 1. uses =:results pp= (and\n looks\n like\n this\n)
 2. uses its own ~pprint~, and =:results output= (and looks correct)

I expected example 2's output from both 1 and 2.

Here's the data to pretty-print:

#+name: columnar-stuff
| State   | Bird  |
| New York| Eastern Bluebird  |
| New Jersey  | Eastern Goldfinch |
| Connecticut | Penguin   |

Here is an attempt using =:results pp=:

#+begin_src clojure :exports both :results pp :var rows=columnar-stuff
rows
#+end_src

#+RESULTS:
: ((\State\ \Bird\)\n (\New York\ \Eastern Bluebird\)\n (\New
Jersey\ \Eastern Goldfinch\)\n (\Connecticut\ \Penguin\))\n

Here is a successful (but uglier) src block with an explicit ~pprint~,
and =:results output=:

#+begin_src clojure :exports both :results output :var rows=columnar-stuff
(clojure.pprint/pprint rows)
#+end_src

#+RESULTS:
: ((State Bird)
:  (New York Eastern Bluebird)
:  (New Jersey Eastern Goldfinch)
:  (Connecticut Penguin))

I would prefer =:results pp= to produce the same effect as the explicit
~pprint~, because keeping the ~pprint~ out of the published src block makes
the presentation clearer.


[O] org-clojure - How to emit an example block?

2014-02-08 Thread Phill Wolf
How can a Clojure source block contribute its standard-output results as an
example block?  I tried :results output org but it expressed the standard
output as a quoted string with \n's where I expected newlines.  For a point
of comparison, org-python seems to be able to do what I want, if begin_src
org is effectively the same as begin_example.  (Is it?)

#+BEGIN_SRC clojure :results output org :exports both
(println Hello)
(println world)
#+END_SRC

#+RESULTS:
#+BEGIN_SRC org
Hello\nworld\n
#+END_SRC


#+BEGIN_SRC python :results output org :exports both
print Hello
print world
#+END_SRC

#+RESULTS:
#+BEGIN_SRC org
Hello
world
#+END_SRC


Re: [O] org-clojure - How to emit an example block?

2014-02-08 Thread Phill Wolf
ob-clojure.el should use separate cider functions for value and output
results, in order to avoid expressing standard output as some kind of
programming-language string with embedded \n notation.  I experimentally
adjusted my copy of ob-clojure (obtained from git clone -b master today)
like this:

(1) In the cider block, access the result-params.
(2) Put either 'cider-get-value or 'cider-get-raw-value into a variable,
depending on the result-params.
(3) funcall the variable instead of using cider-get-raw-value directly.
(0) Up at the top, add a declare-function for cider-get-value, next to the
declare-function for cider-get-raw-value.

(defun org-babel-execute:clojure (body params)
  Execute a block of Clojure code with Babel.
  (let ((expanded (org-babel-expand-body:clojure body params))
result)
(case org-babel-clojure-backend
  (cider
   (require 'cider)
   (let* ((result-params (cdr (assoc :result-params params)))
  (cider-call-fn (cond ((member output result-params)
'cider-get-value)
   ((member value result-params)
'cider-get-raw-value)
   (t 'cider-get-raw-value
 (setq result
   (or (funcall cider-call-fn [...]

Together with :wrap example as suggested by Thomas S. Dye, the results are
exemplary.


[O] ob-clojure: presentation of map structures?

2014-02-01 Thread Phill Wolf
How may I use an Org document to illustrate Clojure src blocks that produce
Clojure data structures -- particularly maps -- as pretty-printed text?  I
think I am using Org master in Emacs 24.3.

#+BEGIN_SRC clojure :results value what options?
(zipmap
  [Peru Paris Sankt-Peterburg Philadelphia Plattsburgh Pluto]
  (range))
#+END_SRC

By the way, Clojure pprint makes the value into the following, which would
be very respectable (with the addition of : org markup) as a result block
in the Org buffer:

{Pluto 5,
 Plattsburgh 4,
 Philadelphia 3,
 Putingrad 2,
 Paris 1,
 Peru 0}

Floundering among the options, I tried :results value pp.  It yielded this:

: {\Pluto\ 5,\n \Plattsburgh\ 4,\n \Philadelphia\ 3,\n
\Sankt-Peterburg\ 2,\n \Paris\ 1,\n \Peru\ 0}\n

pprint's good intentions are evident, but they collided with a superior
force.


Re: [O] Clojure Code Block Results not Tabularized

2014-01-29 Thread Phill Wolf
It is better.  To really stress it, I tried a two-row table:

#+begin_src clojure :results table
  [[:ny :nj :ct]
   [  7   9   4]]
#+end_src

#+RESULTS:
| :ny | :nj | :ct |
|   7 |   9 |   4 |


On Wed, Jan 29, 2014 at 10:28 AM, Bastien b...@gnu.org wrote:

 Eric Schulte schulte.e...@gmail.com writes:

  Try evaluating the following and see how it works.

 It works fine for me:

 ,
 | #+BEGIN_SRC clojure :results table
 | (map #(* %1 3) '(1 2 3))
 | #+END_SRC
 |
 | #+RESULTS:
 | | 3 | 6 | 9 |
 `

  This simply copies
  the results handling from the slime backend to the cider backend (which
  currently does not appear to have any results handling).  While you're
  at it the nrepl results handling looks broken to me as well.

 Yep.

 Greg, please test Eric's function above for all your use cases and let
 us know if it covers them all -- then I'll fix this and the nrepl case
 too.

 Thanks Eric!

 --
  Bastien