emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Daniel Kraus <daniel@kraus.my>
To: Ihor Radchenko <yantar92@posteo.net>
Cc: numbchild@gmail.com, Bastien <bzg@gnu.org>, emacs-orgmode@gnu.org
Subject: Re: [PATCH] Fix ob-clojure handling source block variable's value is a org-mode table or list
Date: Thu, 27 Oct 2022 16:09:34 +0200	[thread overview]
Message-ID: <874jvp9wsg.fsf@kraus.my> (raw)
In-Reply-To: <87r0yvoycr.fsf@localhost>

[-- Attachment #1: Type: text/plain, Size: 1634 bytes --]

Hi!

Ihor Radchenko <yantar92@posteo.net> writes:

> "Christopher M. Miles" <numbchild@gmail.com> writes:
>> Without this patch, it will report error "class java.lang.ClassCastException" from CIDER.
>
> Bastien, could you please take a look? I was unable to setup clojure dev
> environment on my machine for testing. So, I am not able to confirm if
> the issue exists.

Just in case you want to play around with Clojure, installing babashka
(https://github.com/babashka/babashka) is a single binary and very simple to install.

>>  		 ;; Variables binding.
>>  		 (if (null vars) (org-trim body)
>> -		   (format "(let [%s]\n%s)"
>> -			   (mapconcat
>> -			    (lambda (var)
>> -			      (format "%S %S" (car var) (cdr var)))
>> -			    vars
>> -			    "\n      ")
>> -			   body))))))
>> +                   ;; variable's value is a list from org-mode passed table or list.
>> +		   (if (listp (cdr (car vars)))
>
> This test is fishy. It only tests for the first variable assignment.
> What if you have multiple vars some being tables and some not?

I looked at `ob-lisp.el` and simply always quoting seems to be working.
See attached patch and here's my test (based from Chrisophers example):

--cut--

#+NAME: ob-clojure-table-test
| a | b | c |
|---+---+---|
| 1 | 2 | 3 |

#+NAME: ob-clojure-table-test-2
| a | b | c |
|---+---+---|
| 1 | 2 | 3 |
| 4 | 5 | 6 |

#+begin_src clojure :var v1=42 :var v2="foobar" :var v3=ob-clojure-table-test :var v4=ob-clojure-table-test-2 :results output
(prn (+ v1 5))
(prn v2)
(prn v3)
(prn v4)
#+end_src

#+RESULTS:
: 47
: "foobar"
: ((1 2 3))
: ((1 2 3) (4 5 6))

--cut--

Cheers,
  Daniel

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-lisp-ob-clojure.el-Fix-header-argument-var-binding.patch --]
[-- Type: text/x-patch, Size: 999 bytes --]

From 1a2fa382e7a5925d4b85d90f1fe4ac7c012f81a4 Mon Sep 17 00:00:00 2001
From: Daniel Kraus <daniel@kraus.my>
Date: Thu, 27 Oct 2022 16:04:02 +0200
Subject: [PATCH] lisp/ob-clojure.el: Fix header argument :var binding

* lisp/ob-clojure.el (org-babel-expand-body:clojure): Always quote
the variables passed from org-mode in clojure let binding.
When a variable is a table or list, it's value is is "(..data..)"
and without quotes, clojure would try to execute the first
value as a function.
---
 lisp/ob-clojure.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/ob-clojure.el b/lisp/ob-clojure.el
index 0649469b3..c76a3f013 100644
--- a/lisp/ob-clojure.el
+++ b/lisp/ob-clojure.el
@@ -132,7 +132,7 @@ or set the `:backend' header argument"))))
 		   (format "(let [%s]\n%s)"
 			   (mapconcat
 			    (lambda (var)
-			      (format "%S %S" (car var) (cdr var)))
+			      (format "%S '%S" (car var) (cdr var)))
 			    vars
 			    "\n      ")
 			   body))))))
-- 
2.38.1


  reply	other threads:[~2022-10-27 14:18 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <62520bbc.1c69fb81.d855b.549fSMTPIN_ADDED_BROKEN@mx.google.com>
2022-10-26  7:09 ` [PATCH] Fix ob-clojure handling source block variable's value is a org-mode table or list Ihor Radchenko
2022-10-27 14:09   ` Daniel Kraus [this message]
2022-10-28  3:56     ` Ihor Radchenko
2022-10-28  8:51     ` Bastien Guerry
2022-10-28  9:09       ` Daniel Kraus
2022-10-28 10:22         ` Bastien
2022-10-28 21:09           ` Daniel Kraus
2022-10-29  8:08             ` Bastien
2022-10-30 11:21               ` Auto detect ob-clojure backend (was: [PATCH] Fix ob-clojure handling source block variable's value is a org-mode table or list) Daniel Kraus
2022-10-30 12:02                 ` Ihor Radchenko
2022-10-30 12:48                   ` Daniel Kraus
2022-10-30 13:25                     ` Ihor Radchenko
2022-10-30 14:12                       ` Auto detect ob-clojure backend Bastien Guerry
2022-10-30 20:04                     ` Auto detect ob-clojure backend (was: [PATCH] Fix ob-clojure handling source block variable's value is a org-mode table or list) Tim Cross
2022-10-30 20:26                       ` Daniel Kraus
2022-10-31  1:31                     ` Christopher M. Miles
     [not found] <m2lewez8zh.fsf@numbchild>
2022-09-19  4:23 ` [PATCH] Fix ob-clojure handling source block variable's value is a org-mode table or list Christopher M. Miles
2022-10-29  4:19 ` Christopher M. Miles
2022-10-29  5:56   ` Ihor Radchenko
2022-10-29 11:18     ` Daniel Kraus
2022-04-09 13:19 Christopher M. Miles

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=874jvp9wsg.fsf@kraus.my \
    --to=daniel@kraus.my \
    --cc=bzg@gnu.org \
    --cc=emacs-orgmode@gnu.org \
    --cc=numbchild@gmail.com \
    --cc=yantar92@posteo.net \
    /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).