emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [babel] hemorrhaging at the bleeding edge: using clojure
@ 2011-04-27  7:56 Eric S Fraga
  2011-04-27 13:10 ` Eric Schulte
  0 siblings, 1 reply; 8+ messages in thread
From: Eric S Fraga @ 2011-04-27  7:56 UTC (permalink / raw)
  To: emacs-orgmode

Hi all!

I have started using clojure for some serious programming and,
obviously, org comes to mind as my development environment, having very
successfully used org+babel for Octave code development.  Clojure is
installed just fine and I have been using leiningen for project
management up to now (just to get started).

However, in trying to use org, I am hitting a wall in getting clojure
source code blocks to be evaluated.  Can somebody on the list that has
been using clojure with org-babel please help me get going?  I am
getting stuck in getting the whole slime or swank or whatever bits that
are necessary working in Emacs 24.0.x...

I have searched extensively on the web and have tried a number of
approaches, including elpa to install clojure-mode, slime, et al., as
suggested by the =org-contrib/babel/languages/ob-doc-clojure= tutorial
on Worg, but have not yet managed to get a working setup.  In
particular, depending on the version of elpa I use (this is where the
/bleeding edge/ issue in my subject above comes in), I get different
errors.  With the latest version of elpa, I cannot find the
swank-clojure package!  With older versions, I cannot get slime to
install.  Sigh.

I am quite surprised at the difficulty in getting a proper lisp support
installed in Emacs!

Any advice more than welcome!

Thanks,
eric

-- 
: Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 24.0.50.1
: using Org-mode version 7.5 (release_7.5.209.g1a687)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [babel] hemorrhaging at the bleeding edge: using clojure
  2011-04-27  7:56 [babel] hemorrhaging at the bleeding edge: using clojure Eric S Fraga
@ 2011-04-27 13:10 ` Eric Schulte
  2011-04-27 15:50   ` Eric S Fraga
  2011-04-28 16:53   ` Eric S Fraga
  0 siblings, 2 replies; 8+ messages in thread
From: Eric Schulte @ 2011-04-27 13:10 UTC (permalink / raw)
  To: emacs-orgmode

Eric S Fraga <e.fraga@ucl.ac.uk> writes:

> Hi all!
>
> I have started using clojure for some serious programming and,
> obviously, org comes to mind as my development environment, having very
> successfully used org+babel for Octave code development.  Clojure is
> installed just fine and I have been using leiningen for project
> management up to now (just to get started).
>
> However, in trying to use org, I am hitting a wall in getting clojure
> source code blocks to be evaluated.  Can somebody on the list that has
> been using clojure with org-babel please help me get going?  I am
> getting stuck in getting the whole slime or swank or whatever bits that
> are necessary working in Emacs 24.0.x...
>
> I have searched extensively on the web and have tried a number of
> approaches, including elpa to install clojure-mode, slime, et al., as
> suggested by the =org-contrib/babel/languages/ob-doc-clojure= tutorial
> on Worg, but have not yet managed to get a working setup.  In
> particular, depending on the version of elpa I use (this is where the
> /bleeding edge/ issue in my subject above comes in), I get different
> errors.  With the latest version of elpa, I cannot find the
> swank-clojure package!  With older versions, I cannot get slime to
> install.  Sigh.
>

I would suggest using that latest version of ELPA, and adding the
following repository sources to your ELPA archives...

#+srcname: starter-kit-elpa
#+begin_src emacs-lisp 
  (require 'package)
  (add-to-list 'package-archives
               '("original" . "http://tromey.com/elpa/"))
  (add-to-list 'package-archives
               '("technomancy" . "http://repo.technomancy.us/emacs/") t)
  ;; (add-to-list 'package-archives
  ;;              '("marmalade" . "http://marmalade-repo.org/packages/") t) 
  (package-initialize)
#+end_src

This should result in the correct collection of packages being made
available.  Once that is done I've used something like the following
successfully in the past.

#+begin_src emacs-lisp
  ;; clojure
  (setq swank-clojure-classpath "/home/eschulte/.clojure.d/ext/")
  (require 'clojure-mode)
  (require 'swank-clojure)
  (require 'slime)
  (require 'slime-repl)
  (setq swank-clojure-binary "/home/eschulte/bin/clj-env"
        swank-clojure-jar-path "/home/eschulte/.clojure.d/ext/clojure-1.2.0.jar"
        slime-lisp-implementations
        (cons `(clojure ,(swank-clojure-cmd) :init swank-clojure-init)
              (remove-if #'(lambda (x) (eq (car x) 'clojure))
                         slime-lisp-implementations)))
  
  ;; don't know why this is needed all of a sudden
  (add-hook 'clojure-mode-hook (lambda () (font-lock-mode t)))
  
  (setf slime-default-lisp 'clojure)
#+end_src

>
> I am quite surprised at the difficulty in getting a proper lisp support
> installed in Emacs!
>

I've found Clojure to be much harder to configure for working with Emacs
than traditional common lisp environments.  Even now, although I can run
multiple different versions of common lisp side-by-side, I am unable to
activate the Clojure portion of my Emacs configuration without breaking
common lisp support.  I guess my point is that Clojure is a special case
of lisp in this instance...

>
> Any advice more than welcome!
>

Once you have slime working, then Babel code blocks should be trivial
(they rely on a slime session).  Be sure to use the ":package" header
argument to specify the namespace in which to evaluate your clojure
code.

Best -- Eric

>
> Thanks,
> eric

-- 
Eric Schulte
http://cs.unm.edu/~eschulte/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [babel] hemorrhaging at the bleeding edge: using clojure
  2011-04-27 13:10 ` Eric Schulte
@ 2011-04-27 15:50   ` Eric S Fraga
  2011-04-28 16:53   ` Eric S Fraga
  1 sibling, 0 replies; 8+ messages in thread
From: Eric S Fraga @ 2011-04-27 15:50 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode

"Eric Schulte" <schulte.eric@gmail.com> writes:

[...]

> I would suggest using that latest version of ELPA, and adding the
> following repository sources to your ELPA archives...

Done.  Thanks for the more comprehensive list of archives.

[...]

> This should result in the correct collection of packages being made
> available.  Once that is done I've used something like the following
> successfully in the past.
>
> #+begin_src emacs-lisp
>   ;; clojure
>   (setq swank-clojure-classpath "/home/eschulte/.clojure.d/ext/")
>   (require 'clojure-mode)
>   (require 'swank-clojure)
>   (require 'slime)
>   (require 'slime-repl)
>   (setq swank-clojure-binary "/home/eschulte/bin/clj-env"
>         swank-clojure-jar-path "/home/eschulte/.clojure.d/ext/clojure-1.2.0.jar"
>         slime-lisp-implementations
>         (cons `(clojure ,(swank-clojure-cmd) :init swank-clojure-init)
>               (remove-if #'(lambda (x) (eq (car x) 'clojure))
>                          slime-lisp-implementations)))
>   
>   ;; don't know why this is needed all of a sudden
>   (add-hook 'clojure-mode-hook (lambda () (font-lock-mode t)))
>   
>   (setf slime-default-lisp 'clojure)
> #+end_src

This does not quite work for me.  When I try to start slime, swank.jar
is not found.   Should I be downloading this from somewhere specific?

Thanks again,
eric
-- 
: Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 24.0.50.1
: using Org-mode version 7.5 (release_7.5.209.g1a687)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [babel] hemorrhaging at the bleeding edge: using clojure
  2011-04-27 13:10 ` Eric Schulte
  2011-04-27 15:50   ` Eric S Fraga
@ 2011-04-28 16:53   ` Eric S Fraga
  2011-04-28 17:08     ` Eric S Fraga
  2011-04-28 18:22     ` Eric Schulte
  1 sibling, 2 replies; 8+ messages in thread
From: Eric S Fraga @ 2011-04-28 16:53 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode

"Eric Schulte" <schulte.eric@gmail.com> writes:

[...]

> I would suggest using that latest version of ELPA, and adding the
> following repository sources to your ELPA archives...

[...]

> Once you have slime working, then Babel code blocks should be trivial
> (they rely on a slime session).  Be sure to use the ":package" header
> argument to specify the namespace in which to evaluate your clojure
> code.

Eric (and/or anybody else with babel+clojure expertise?),

again, thanks for your help on this but I hope I can continue to bother
you!

I have finally managed to get clojure working in org+babel.  To cut a
very long story short, there were two problems (for the benefit of the
mailing list):

1. I had a previously installed version of slime on my system that was
   conflicting with the new version being installed by elpa.  In moving
   from emacs 23.x to 24.x, a number of old packages remained and slime
   was one of them.  Removing the old version suddenly made things work
   (sort of).

2. Because I'm using clojure as an interface to an existing Java package
   (in-house, written over the past 15 years so a large investment in
   effort), the whole issue of classpaths raised its ugly head (the
   worst aspect of java, IMO).  I finally sorted this out by making my
   own version of the swank-clojure script to automatically include my
   own very complex classpath.

So, now I have a setup in which my clojure code is executed just fine,
Java packages are found as are clojure packages, etc.  However, I cannot
get output into my org file.  For instance, the following code

--8<---------------cut here---------------start------------->8---
    #+srcname: simple
    #+begin_src clojure :results output raw
(variable [-1 1 2 3])
    #+end_src
--8<---------------cut here---------------end--------------->8---

works, in that the output I would expect appears in the =*slime-events*=
buffer: 

--8<---------------cut here---------------start------------->8---
(:emacs-rex
 (swank:interactive-eval-region "(variable [-1 1 2 3])")
 "user" t 17)
(:return
 (:ok "#<Variables x={ -1.0, 1.0, 2.0, 3.0 }>")
 17)
--8<---------------cut here---------------end--------------->8---

(don't worry about what the output says...  Variables is a Java object I
need to work with.)

The problem is that nothing appears in the org file; instead, I get the
following error message:

--8<---------------cut here---------------start------------->8---
Evaluate this clojure code block (simple) on your system? (y or n)  y
executing Clojure code block (simple)...
org-babel-execute:clojure: Invalid read syntax: "#"
--8<---------------cut here---------------end--------------->8---

This is very confusing...  From looking at the relevant elisp code:

--8<---------------cut here---------------start------------->8---
(read
     (slime-eval
      `(swank:interactive-eval-region
        ,(buffer-substring-no-properties (point-min) (point-max)))
      (cdr (assoc :package params))))
--8<---------------cut here---------------end--------------->8---

=read= is trying to interpret the code.  But I'm not sure what this is
intended to do in this case.

If I change my code to use the Java =.toString= method on my object, and
ask for either output or value results, it works:

--8<---------------cut here---------------start------------->8---
    #+srcname: simple
    #+begin_src clojure :results value
(.toString (variable [-1 1 2 3]))
    #+end_src

    #+results: simple
    : x={ -1.0, 1.0, 2.0, 3.0 }
--8<---------------cut here---------------end--------------->8---


Can you help at all?  I am a little confused, to say the least :(

But happy in that I've made some progress at least!  Although it *has*
taken me all afternoon!

Thanks again and sorry for the long diatribe,
eric

-- 
: Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 24.0.50.1
: using Org-mode version 7.5 (release_7.5.222.g0846a)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [babel] hemorrhaging at the bleeding edge: using clojure
  2011-04-28 16:53   ` Eric S Fraga
@ 2011-04-28 17:08     ` Eric S Fraga
  2011-04-28 18:22     ` Eric Schulte
  1 sibling, 0 replies; 8+ messages in thread
From: Eric S Fraga @ 2011-04-28 17:08 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode

(followup to my long email a few minutes ago)

I should have added that the output I expect does all appear in the
=*slime-repl clojure*= buffer even if it never appears in the org
buffer.

Maybe I've misunderstood what ob-clojure is meant to do?

thanks,
eric

-- 
: Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 24.0.50.1
: using Org-mode version 7.5 (release_7.5.222.g0846a)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [babel] hemorrhaging at the bleeding edge: using clojure
  2011-04-28 16:53   ` Eric S Fraga
  2011-04-28 17:08     ` Eric S Fraga
@ 2011-04-28 18:22     ` Eric Schulte
  2011-04-28 20:21       ` Eric S Fraga
  1 sibling, 1 reply; 8+ messages in thread
From: Eric Schulte @ 2011-04-28 18:22 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode

[...]
>
> The problem is that nothing appears in the org file; instead, I get the
> following error message:
>
> Evaluate this clojure code block (simple) on your system? (y or n)  y
> executing Clojure code block (simple)...
> org-babel-execute:clojure: Invalid read syntax: "#"
>
> This is very confusing...  From looking at the relevant elisp code:
>
> (read
>      (slime-eval
>       `(swank:interactive-eval-region
>         ,(buffer-substring-no-properties (point-min) (point-max)))
>       (cdr (assoc :package params))))
>
> =read= is trying to interpret the code.  But I'm not sure what this is
> intended to do in this case.
>
> If I change my code to use the Java =.toString= method on my object, and
> ask for either output or value results, it works:
>
>     #+srcname: simple
>     #+begin_src clojure :results value
> (.toString (variable [-1 1 2 3]))
>     #+end_src
>
>     #+results: simple
>     : x={ -1.0, 1.0, 2.0, 3.0 }
>
>
> Can you help at all?  I am a little confused, to say the least :(
>

Yes, I just pushed up a commit which should solve this issue.

Babel tries to read the results, to see if they should be inserted as a
table or verbatim, it will now default to verbatim if reading of the
result throws an error.

Best -- Eric

-- 
Eric Schulte
http://cs.unm.edu/~eschulte/

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [babel] hemorrhaging at the bleeding edge: using clojure
  2011-04-28 18:22     ` Eric Schulte
@ 2011-04-28 20:21       ` Eric S Fraga
  2011-04-28 20:41         ` Eric Schulte
  0 siblings, 1 reply; 8+ messages in thread
From: Eric S Fraga @ 2011-04-28 20:21 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode

"Eric Schulte" <schulte.eric@gmail.com> writes:

> [...]
>>
>> The problem is that nothing appears in the org file; instead, I get the
>
>> following error message:
>>
>> Evaluate this clojure code block (simple) on your system? (y or n)  y
>> executing Clojure code block (simple)...
>> org-babel-execute:clojure: Invalid read syntax: "#"

[...]

>> Can you help at all?  I am a little confused, to say the least :(
>>
>
> Yes, I just pushed up a commit which should solve this issue.

Brilliant.  The error message is gone and I get the results I expect!
Many thanks.

-- 
: Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 24.0.50.1
: using Org-mode version 7.5 (release_7.5.223.g4a86)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [babel] hemorrhaging at the bleeding edge: using clojure
  2011-04-28 20:21       ` Eric S Fraga
@ 2011-04-28 20:41         ` Eric Schulte
  0 siblings, 0 replies; 8+ messages in thread
From: Eric Schulte @ 2011-04-28 20:41 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode

Eric S Fraga <e.fraga@ucl.ac.uk> writes:

> "Eric Schulte" <schulte.eric@gmail.com> writes:
>
>> [...]
>>>
>>> The problem is that nothing appears in the org file; instead, I get the
>>
>>> following error message:
>>>
>>> Evaluate this clojure code block (simple) on your system? (y or n)  y
>>> executing Clojure code block (simple)...
>>> org-babel-execute:clojure: Invalid read syntax: "#"
>
> [...]
>
>>> Can you help at all?  I am a little confused, to say the least :(
>>>
>>
>> Yes, I just pushed up a commit which should solve this issue.
>
> Brilliant.  The error message is gone and I get the results I expect!
> Many thanks.

Wonderful,

Perhaps at some point it would be worth trying something more
complicated in the case of an error reading as pure lisp, e.g., trying
to invoke a to_string or (if the object designer is an Org-mode fan) a
to_org method on the object being returned...

Best -- Eric

also, off topic, another option for lisp on the JVM is ABCL a full
implementation of Common Lisp on the JVM http://armedbear.org/abcl.html

-- 
Eric Schulte
http://cs.unm.edu/~eschulte/

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-04-28 20:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-27  7:56 [babel] hemorrhaging at the bleeding edge: using clojure Eric S Fraga
2011-04-27 13:10 ` Eric Schulte
2011-04-27 15:50   ` Eric S Fraga
2011-04-28 16:53   ` Eric S Fraga
2011-04-28 17:08     ` Eric S Fraga
2011-04-28 18:22     ` Eric Schulte
2011-04-28 20:21       ` Eric S Fraga
2011-04-28 20:41         ` Eric Schulte

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).