emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nick Dokos <ndokos@gmail.com>
To: emacs-orgmode@gnu.org
Subject: Re: Babel and clojure vars
Date: Tue, 27 Sep 2016 15:45:31 -0400	[thread overview]
Message-ID: <87twd1unxg.fsf@gmail.com> (raw)
In-Reply-To: CAFAhFSW_WDxJqgpq4whuX3BASbh0FdOr8B0Wy1jchxkoBf8Bog@mail.gmail.com

Lawrence Bottorff <borgauf@gmail.com> writes:

> Once before I was wondering why :vars doesn't seem to work properly with clojure. This works:
>
> #+begin_src clojure :var a='(1 2 3 4 5)
> (count a)
> #+end_src
>
> #+RESULTS:
> : 5
>
> as well as this
>
> #+begin_src emacs-lisp :var a=(number-sequence 1 5)
> a
> #+end_src
>
> #+RESULTS: num-seq-test1
> | 1 | 2 | 3 | 4 | 5 |
>
> but this is a no go. . . .
>
> #+begin_src clojure c=(range 10)
> (count c)
> #+end_src
>

Is `range' a clojure function? If so, that's expected:

(info "(org) var") says:

,----
|    The values passed to arguments can either be literal values,
| references, or Emacs Lisp code (see *note Emacs Lisp evaluation of
| variables: var.).
`----

[The syntax is wrong too: it should read

#+begin_src clojure :var c=(range 10)
 (count c)
#+end_src

but it's not going to work unless you define an emacs-lisp function called range
and teach it to emacs.]

The following works (I don't have clojure installed here, so I replaced it with scheme):

--8<---------------cut here---------------start------------->8---
#+BEGIN_SRC emacs-lisp
(defun range (N)
  (if (<= N 1)
      (list N)
    (nconc (range (- N 1)) (list N))))
#+END_SRC

#+begin_src scheme :var c=(range 10)
(define (count l)
   (if (null? l)
     0
     (1+ (count (cdr l)))))

(count c)
#+end_src

#+RESULTS:
: 10
--8<---------------cut here---------------end--------------->8---

-- 
Nick

      reply	other threads:[~2016-09-27 19:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-27 19:03 Babel and clojure vars Lawrence Bottorff
2016-09-27 19:45 ` Nick Dokos [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87twd1unxg.fsf@gmail.com \
    --to=ndokos@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).