From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Eric Schulte" Subject: Re: Org-Babel - Clojure & Lazy Sequences Bug Date: Thu, 25 Nov 2010 10:40:07 -0700 Message-ID: <87vd3lz4i0.fsf@gmail.com> References: <87k4kqpc4q.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from [140.186.70.92] (port=42433 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PLfns-00055w-6G for emacs-orgmode@gnu.org; Thu, 25 Nov 2010 12:40:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PLfnq-00063b-Sy for emacs-orgmode@gnu.org; Thu, 25 Nov 2010 12:40:16 -0500 Received: from mail-gw0-f41.google.com ([74.125.83.41]:36714) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PLfnq-00063V-Oa for emacs-orgmode@gnu.org; Thu, 25 Nov 2010 12:40:14 -0500 Received: by gwaa12 with SMTP id a12so692833gwa.0 for ; Thu, 25 Nov 2010 09:40:14 -0800 (PST) In-Reply-To: (Rick Moynihan's message of "Wed, 24 Nov 2010 01:51:44 +0000") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Rick Moynihan Cc: emacs-orgmode@gnu.org, Joel Boehland --=-=-= Content-Type: text/plain Hi Rick, I'm not quite sure what the best permanent solution would be. I'm tempted to switch to a drastically stripped down version of Clojure interaction which relies very heavily on slime. I'm attaching a first pass at this which allows for slime-based execution, can assign variables, handles lazy evaluation, etc... The downside to this new version is that it doesn't support buffer-based sessions or external evaluation, but the upside is that it is incredibly simple, and by relying so heavily on slime it should be very robust. Once this is enhanced with some code to start slime, and a simple :session setup (namely the ability to grab the slime context from a buffer specified by :session) I may prefer this to the existing ob-clojure. I'd be interested to hear what others think. Personally I'm happy to lose external evaluation and switch to purely slime-based evaluation, but I don't want to trash it if it is an important part of someones work flow. Best -- Eric --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=ob-clojure.el Content-Transfer-Encoding: quoted-printable ;;; ob-clojure.el --- org-babel functions for clojure evaluation ;; Copyright (C) 2009, 2010 Free Software Foundation, Inc. ;; Author: Joel Boehland, Eric Schulte ;; Keywords: literate programming, reproducible research ;; Homepage: http://orgmode.org ;; Version: 7.3 ;; This file is part of GNU Emacs. ;; GNU Emacs is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs. If not, see . ;;; Commentary: ;;; ob support for evaluating clojure code, relies on slime for all eval ;;; Requirements: ;;; A working clojure install. This also implies a working java executable ;;; clojure-mode ;;; slime ;;; swank-clojure ;;; By far, the best way to install these components is by following ;;; the directions as set out by Phil Hagelberg (Technomancy) on the ;;; web page: http://technomancy.us/126 ;;; Code: (require 'ob) (declare-function slime-eval "ext:slime" (sexp &optional package)) (add-to-list 'org-babel-tangle-lang-exts '("clojure" . "clj")) (defvar org-babel-default-header-args:clojure '()) (defun org-babel-expand-body:clojure (body params) "Expand BODY according to PARAMS, return the expanded body." (let* ((vars (mapcar #'cdr (org-babel-get-header params :var))) (print-level nil) (print-length nil) (body (if (> (length vars) 0) (concat "(let [" (mapconcat (lambda (var) (format "%S (quote %S)" (car var) (cdr var))) vars "\n ") "]\n" body ")") body))) body)) (defun org-babel-execute:clojure (body params) "Execute a block of Clojure code with Babel." (require 'slime) (require 'swank-clojure) (with-temp-buffer (insert (org-babel-expand-body:clojure body params)) (read (slime-eval `(swank:interactive-eval-region=20 ,(buffer-substring-no-properties (point-min) (point-max))) (cdr (assoc :package params)))))) (provide 'ob-clojure) ;; arch-tag: a43b33f2-653e-46b1-ac56-2805cf05b7d1 ;;; ob-clojure.el ends here --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Rick Moynihan writes: > Hi Eric, > > Sorry for the delay in getting back to you. > > I can confirm the fix you quoted below works for me also. > > I've not been using any of the multiple session features, so I haven't > run into the other problems you mention. > > Any idea on what a more permanent solution might be? > > R. > > On 6 November 2010 17:58, Eric Schulte wrote: >> Hi Rick, >> >> I've noticed this as well. =C2=A0I'm not the original author of ob-cloju= re.el >> (Joel Boehland is), so I'm not sure how the clojure interaction >> currently works, although I know it makes heavy usage of slime. =C2=A0Th= ere >> must be an existing mechanism used by slime to unroll these lazy >> evaluations, for example in the repl (range 10) *is* expanded >> >> user> (range 10) >> (0 1 2 3 4 5 6 7 8 9) >> >> I'm using clojure extensively in my studies so I have all the more >> reason to try to figure this out. =C2=A0I'll put this on my stack. >> >> BTW: I've noticed that I am unable to get Clojure code blocks to play >> nicely with existing slime sessions, say for example I have some large >> piece of data in scope in a slime sessions and I'd like to access that >> data from a clojure code block and dump some analysis to an Org-mode >> document. =C2=A0I have not yet found out how to make this work. =C2=A0If= you have, >> I'd love to hear how, otherwise I'll look into this as well. >> >> Best -- Eric >> >> Having just looked at this quickly, the following function over-defines >> `org-babel-execute:clojure' s.t. =C2=A0the body of the code block is sen= t to >> the superior list in the same manner as when calling `slime-eval-defun' >> from within a .clj file. =C2=A0While this doesn't handle starting up clo= jure >> instances or differentiate between session and external evaluation it >> should fix the issues mentioned above and could be the beginning of a >> permanent solution. >> >> #+begin_src emacs-lisp >> =C2=A0(defun org-babel-execute:clojure (body params) >> =C2=A0 =C2=A0(with-temp-buffer >> =C2=A0 =C2=A0 =C2=A0(insert body) >> =C2=A0 =C2=A0 =C2=A0(read >> =C2=A0 =C2=A0 =C2=A0 (slime-eval >> =C2=A0 =C2=A0 =C2=A0 =C2=A0`(swank:interactive-eval-region >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0,(buffer-substring-no-properties (poin= t-min) (point-max))))))) >> #+end_src >> >> which then results in >> >> #+begin_src clojure >> =C2=A0(map (fn [el] (list el (* el el))) (range 10)) >> #+end_src >> >> evaluating to >> >> #+results: >> | 0 | =C2=A00 | >> | 1 | =C2=A01 | >> | 2 | =C2=A04 | >> | 3 | =C2=A09 | >> | 4 | 16 | >> | 5 | 25 | >> | 6 | 36 | >> | 7 | 49 | >> | 8 | 64 | >> | 9 | 81 | >> >> Rick Moynihan writes: >> >>> I have the following org file: >>> >>> #+BEGIN_SRC clojure >>> (range 10) >>> #+END_SRC >>> >>> #+results: >>> : clojure.lang.LazySeq@f35bf8c6 >>> >>> Where as I would expect to see the sequence. =C2=A0Evaluating the code >>> inside a doall doesn't seem to do anything either: >>> >>> #+BEGIN_SRC clojure >>> (doall (range 10)) >>> #+END_SRC >>> >>> #+results: >>> : clojure.lang.LazySeq@f35bf8c6 >>> >>> Is there any parameter I can pass to the block to get the code to >>> execute in a doall and return the sequence values rather than the >>> lazy-seq object itself? >>> >>> R. >>> >>> _______________________________________________ >>> Emacs-orgmode mailing list >>> Please use `Reply All' to send replies to the list. >>> Emacs-orgmode@gnu.org >>> http://lists.gnu.org/mailman/listinfo/emacs-orgmode >> --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode --=-=-=--