Re: Auto detect ob-clojure backend (was: [PATCH] Fix ob-clojure handling source block variable's value is a org-mode table or list)

2022-10-30 Thread Christopher M. Miles

Daniel Kraus  writes:

> Ihor Radchenko  writes:
>
>> Daniel Kraus  writes:
>>
>>> +(defcustom org-babel-clojure-backend (cond
>>> +  ((executable-find "bb") 'babashka)
>>> +  ((executable-find "nbb") 'nbb)
>>> +  ((featurep 'cider) 'cider)
>>> +  ((featurep 'inf-clojure) 
>>> 'inf-clojure)
>>> +  ((featurep 'slime) 'slime)
>>> + (t nil))
>>
>> What if users have, say, cider installed and also babashka executable?
>> Will it be expected to use babashka?
>
> Yes. The only thing that makes me slightly hesitant is that e.g.
> someone doesn't have `bb` installed. Executes clojure source blocks
> which are then evaluated in, let's say cider.
> Then they install `bb` and the next time they start Emacs, the same
> source block on re-evaluation would be executed with babashka.
>
> I think this is still the best out of the box experience as it
> "just works" for most users without having to customise something
> and if they want it fixed, they can pin it to a certain backend.
>
> What's your opinion?
>
> Cheers,
>   Daniel

I vote for use Clojure CLI like bb as default backend. Keeping defcustom
option for user to setting default backend is fine.

-- 

[ stardiviner ]
I try to make every word tell the meaning that I want to express without 
misunderstanding.

Blog: https://stardiviner.github.io/
IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3


signature.asc
Description: PGP signature


Re: Auto detect ob-clojure backend (was: [PATCH] Fix ob-clojure handling source block variable's value is a org-mode table or list)

2022-10-30 Thread Daniel Kraus


Tim Cross  writes:

> I think bb is a much better solution from a babel perspective and would
> love to see it as the default, even when you have both bb and cider
> installed.

I just installed the patch. So if you have `bb` in your path, ob-clojure
should use babashka as default and only fall back to cider when it's not.

Currently it looks for bb, and then next `nbb` before cider.
Now I realise that nbb shouldn't even be in that list at all but instead
should be the default for `org-babel-execute:clojurescript`.

> I stopped using clojure in org because it was way too fragile -
> depending heavily on cider features which often changed. However, now we
> have babashka and nbb, I'm thinking about using org again with
> clojure.

Happy to hear feedback if you have any :)

> I recall looking at the babel code for clojure some time back to see if
> it could be made simpler and more reliable. However, there wasn't much
> that could be improved on given the design of cider and its focus on
> interactive clojure development.

I agree, cider is a pretty heavy library.
And I feel that if you have already "jacked in" in cider, you simply
eval straight from you clj(s) code instead of using org babel.
(Maybe in combination with clerk or something if you want it more literal)

> I then thought using something like the
> Clojure CLI tools might be the way to go.

I think I'll add a backend for the Clojure CLI tools.
Should be similar simple as bb and nbb with slower startup time,
but you would get a JVM Clojure for it.

> Now I feel that babashka for clojure and nbb for clojurescript
> might be the right answer.

Agree. bb default for Clojure and nbb for ClojureScript.

Thanks,
  Daniel



Re: Auto detect ob-clojure backend (was: [PATCH] Fix ob-clojure handling source block variable's value is a org-mode table or list)

2022-10-30 Thread Tim Cross


Daniel Kraus  writes:

> Ihor Radchenko  writes:
>
>> Daniel Kraus  writes:
>>
>>> +(defcustom org-babel-clojure-backend (cond
>>> +  ((executable-find "bb") 'babashka)
>>> +  ((executable-find "nbb") 'nbb)
>>> +  ((featurep 'cider) 'cider)
>>> +  ((featurep 'inf-clojure) 
>>> 'inf-clojure)
>>> +  ((featurep 'slime) 'slime)
>>> + (t nil))
>>
>> What if users have, say, cider installed and also babashka executable?
>> Will it be expected to use babashka?
>
> Yes. The only thing that makes me slightly hesitant is that e.g.
> someone doesn't have `bb` installed. Executes clojure source blocks
> which are then evaluated in, let's say cider.
> Then they install `bb` and the next time they start Emacs, the same
> source block on re-evaluation would be executed with babashka.
>
> I think this is still the best out of the box experience as it
> "just works" for most users without having to customise something
> and if they want it fixed, they can pin it to a certain backend.
>
> What's your opinion?
>
> Cheers,
>   Daniel

Just chime in with my 2 cents.

I think bb is a much better solution from a babel perspective and would
love to see it as the default, even when you have both bb and cider
installed.

I stopped using clojure in org because it was way too fragile -
depending heavily on cider features which often changed. However, now we
have babashka and nbb, I'm thinking about using org again with clojure.

I recall looking at the babel code for clojure some time back to see if
it could be made simpler and more reliable. However, there wasn't much
that could be improved on given the design of cider and its focus on
interactive clojure development. I then thought using something like the
Clojure CLI tools might be the way to go. Now I feel that babashka for
clojure and nbb for clojurescript might be the right answer. 



Re: Auto detect ob-clojure backend (was: [PATCH] Fix ob-clojure handling source block variable's value is a org-mode table or list)

2022-10-30 Thread Ihor Radchenko
Daniel Kraus  writes:

>> What if users have, say, cider installed and also babashka executable?
>> Will it be expected to use babashka?
>
> Yes. The only thing that makes me slightly hesitant is that e.g.
> someone doesn't have `bb` installed. Executes clojure source blocks
> which are then evaluated in, let's say cider.
> Then they install `bb` and the next time they start Emacs, the same
> source block on re-evaluation would be executed with babashka.
>
> I think this is still the best out of the box experience as it
> "just works" for most users without having to customise something
> and if they want it fixed, they can pin it to a certain backend.
>
> What's your opinion?

I agree.

Though if you want to go really fancy, you can utilize org-persist to
store the customization value in persistent cache (org-persist-register),
load it back (org-persist-read), and re-use when the cached backend can
be enabled.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: Auto detect ob-clojure backend (was: [PATCH] Fix ob-clojure handling source block variable's value is a org-mode table or list)

2022-10-30 Thread Daniel Kraus


Ihor Radchenko  writes:

> Daniel Kraus  writes:
>
>> +(defcustom org-babel-clojure-backend (cond
>> +  ((executable-find "bb") 'babashka)
>> +  ((executable-find "nbb") 'nbb)
>> +  ((featurep 'cider) 'cider)
>> +  ((featurep 'inf-clojure) 'inf-clojure)
>> +  ((featurep 'slime) 'slime)
>> +  (t nil))
>
> What if users have, say, cider installed and also babashka executable?
> Will it be expected to use babashka?

Yes. The only thing that makes me slightly hesitant is that e.g.
someone doesn't have `bb` installed. Executes clojure source blocks
which are then evaluated in, let's say cider.
Then they install `bb` and the next time they start Emacs, the same
source block on re-evaluation would be executed with babashka.

I think this is still the best out of the box experience as it
"just works" for most users without having to customise something
and if they want it fixed, they can pin it to a certain backend.

What's your opinion?

Cheers,
  Daniel



Re: Auto detect ob-clojure backend (was: [PATCH] Fix ob-clojure handling source block variable's value is a org-mode table or list)

2022-10-30 Thread Ihor Radchenko
Daniel Kraus  writes:

> Bastien  writes:
>
>> Daniel Kraus  writes:
>>
>>> I think I'll go with the big `cond` above to auto-detect what's
>>> installed. That's probably the best out-of-the-box experience.
>> Indeed, thank you!
>
> I would push the attached patch.

> +(defcustom org-babel-clojure-backend (cond
> +  ((executable-find "bb") 'babashka)
> +  ((executable-find "nbb") 'nbb)
> +  ((featurep 'cider) 'cider)
> +  ((featurep 'inf-clojure) 'inf-clojure)
> +  ((featurep 'slime) 'slime)
> +   (t nil))

What if users have, say, cider installed and also babashka executable? 
Will it be expected to use babashka?

> I'm not sure about the `:package-version` keyword in defcustom.
> I want to say that the default value changed.
> Should I do it this way? Is `(Org . "9.6")` correct as it's unreleased?

Yes. 9.6 is the next release - our main branch is labeled Org 9.6-pre.
So, using 9.6 is correct.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Auto detect ob-clojure backend (was: [PATCH] Fix ob-clojure handling source block variable's value is a org-mode table or list)

2022-10-30 Thread Daniel Kraus

Bastien  writes:

> Daniel Kraus  writes:
>
>> I think I'll go with the big `cond` above to auto-detect what's
>> installed. That's probably the best out-of-the-box experience.
> Indeed, thank you!

I would push the attached patch.
I'm not sure about the `:package-version` keyword in defcustom.
I want to say that the default value changed.
Should I do it this way? Is `(Org . "9.6")` correct as it's unreleased?

Thanks,
  Daniel
>From bd68ece99ce411439db87cd19e44ffbc49677ae3 Mon Sep 17 00:00:00 2001
From: Daniel Kraus 
Date: Sat, 29 Oct 2022 23:20:06 +0200
Subject: [PATCH] ob-clojure.el: Auto detect backend

* lisp/ob-clojure.el (org-babel-clojure-backend): Set the backend
to an available cli program or elisp package.
---
 lisp/ob-clojure.el | 9 -
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/lisp/ob-clojure.el b/lisp/ob-clojure.el
index 5654d5208..25f1c78a6 100644
--- a/lisp/ob-clojure.el
+++ b/lisp/ob-clojure.el
@@ -76,9 +76,16 @@
 (defvar org-babel-default-header-args:clojurescript '())
 (defvar org-babel-header-args:clojurescript '((package . :any)))
 
-(defcustom org-babel-clojure-backend nil
+(defcustom org-babel-clojure-backend (cond
+  ((executable-find "bb") 'babashka)
+  ((executable-find "nbb") 'nbb)
+  ((featurep 'cider) 'cider)
+  ((featurep 'inf-clojure) 'inf-clojure)
+  ((featurep 'slime) 'slime)
+  (t nil))
   "Backend used to evaluate Clojure code blocks."
   :group 'org-babel
+  :package-version '(Org . "9.6")
   :type '(choice
 	  (const :tag "inf-clojure" inf-clojure)
 	  (const :tag "cider" cider)
-- 
2.38.1



[CLOSED] Re: [PATCH] Fix ob-clojure handling source block variable's value is a org-mode table or list

2022-10-29 Thread Christopher M. Miles

Daniel Kraus  writes:

> Hi
>
> Ihor Radchenko  writes:
>> "Christopher M. Miles"  writes:
>>> Any review comments about this patch?
>> I have sent the following comment shortly after your followup:
>
> I even made another post after that, suggesting that the if condition
> is not even needed. Simply always quoting seems to work and is also the
> way it's done in `ob-lisp.el`.
> See https://list.orgmode.org/orgmode/874jvp9wsg@kraus.my/
>
> This simple patch is also already installed. Can you test if that works for 
> you?
>
> And in case you missed it, I made another reply for you bug report
> about inline comments.
> Check https://list.orgmode.org/orgmode/878rl1a1e0@kraus.my/
>
> Thanks,
>   Daniel

Indeed, your solution is better. Sorry that I have not realized your
patch. Thanks for notify me again. Closed this thread now.

-- 

[ stardiviner ]
I try to make every word tell the meaning that I want to express without 
misunderstanding.

Blog: https://stardiviner.github.io/
IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3


signature.asc
Description: PGP signature


Re: [PATCH] Fix ob-clojure handling source block variable's value is a org-mode table or list

2022-10-29 Thread Daniel Kraus
Hi

Ihor Radchenko  writes:
> "Christopher M. Miles"  writes:
>> Any review comments about this patch?
> I have sent the following comment shortly after your followup:

I even made another post after that, suggesting that the if condition
is not even needed. Simply always quoting seems to work and is also the
way it's done in `ob-lisp.el`.
See https://list.orgmode.org/orgmode/874jvp9wsg@kraus.my/

This simple patch is also already installed. Can you test if that works for you?

And in case you missed it, I made another reply for you bug report
about inline comments.
Check https://list.orgmode.org/orgmode/878rl1a1e0@kraus.my/

Thanks,
  Daniel



Re: [PATCH] Fix ob-clojure handling source block variable's value is a org-mode table or list

2022-10-29 Thread Bastien
Daniel Kraus  writes:

> I think I'll go with the big `cond` above to auto-detect what's
> installed. That's probably the best out-of-the-box experience.

Indeed, thank you!

-- 
 Bastien



Re: [PATCH] Fix ob-clojure handling source block variable's value is a org-mode table or list

2022-10-28 Thread Ihor Radchenko
"Christopher M. Miles"  writes:

> Any review comments about this patch?

I have sent the following comment shortly after your followup:

"Christopher M. Miles"  writes:

> +   ;; variable's value is a list from org-mode passed table 
> or list.
> +(if (listp (cdr (car vars)))
> ...
> +   (format "(let [%s]\n%s)"
> +   (mapconcat
> +(lambda (var)
> +  (format "%S '%S" (car var) (cdr var)))
> +vars
> +"\n  ")

Do I miss something, or you only test the first variable assignment here?
What if there are multiple assignments (:var a=X,b=Y)?

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: [PATCH] Fix ob-clojure handling source block variable's value is a org-mode table or list

2022-10-28 Thread Christopher M. Miles

Any review comments about this patch?

"Christopher M. Miles"  writes:

> [[PGP Signed Part:Undecided]]
>
> I bellowing example:
>
> #+begin_src org
> ,#+NAME: ob-clojure-table-test
> | a | b | c |
> |---+---+---|
> | 1 | 2 | 3 |
>
> ,#+NAME: ob-clojure-table-test-2
> | a | b | c |
> |---+---+---|
> | 1 | 2 | 3 |
>
> ,#+begin_src clojure :var kk=ob-clojure-table-test :var 
> kk2=ob-clojure-table-test-2 :results output
> (println kk2)
> (println kk)
> ,#+end_src
>
> #+end_src
>
> Without this patch, it will report error "class java.lang.ClassCastException" 
> from CIDER.
>
> This patch added if condition to handle this table, list type data.
>
> From 948e8c1ff2c9ba1d9c0fe26f9bdaa096bef80a9d Mon Sep 17 00:00:00 2001
> From: stardiviner 
> Date: Sat, 9 Apr 2022 21:14:22 +0800
> Subject: [PATCH] ob-clojure.el: Fix header argument :var binding passed table
>  or list data
>
> * lisp/ob-clojure.el (org-babel-expand-body:clojure): Add if condition
> to handle source block :var passed org-mode table or list data for
> clojure let-binding to avoid java.lang.ClassCastException.
> ---
>  lisp/ob-clojure.el | 25 ++---
>  1 file changed, 18 insertions(+), 7 deletions(-)
>
> diff --git a/lisp/ob-clojure.el b/lisp/ob-clojure.el
> index 5a44b6487..e6614b2d9 100644
> --- a/lisp/ob-clojure.el
> +++ b/lisp/ob-clojure.el
> @@ -101,13 +101,24 @@
>(and (cdr (assq :ns params)) (format "(ns %s)\n" ns))
>;; 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)))
> +   (format "(let [%s]\n%s)"
> +   (mapconcat
> +(lambda (var)
> +  (format "%S '%S" (car var) (cadr var)))
> +vars
> +"\n  ")
> +   body)
> + ;; else, the header argument variable's value is not a 
> list.
> + (format "(let [%s]\n%s)"
> + (mapconcat
> +  (lambda (var)
> +(format "%S %S" (car var) (cdr var)))
> +  vars
> +  "\n  ")
> + body)
> + ))
>  (if (or (member "code" result-params)
>   (member "pp" result-params))
>   (format "(clojure.pprint/pprint (do %s))" body)
> -- 
> 2.35.1
>
> [5. text/x-patch; 
> 0001-ob-clojure.el-Fix-header-argument-var-binding-passed.patch]...


-- 

[ stardiviner ]
I try to make every word tell the meaning that I want to express without 
misunderstanding.

Blog: https://stardiviner.github.io/
IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3


signature.asc
Description: PGP signature


Re: [PATCH] Fix ob-clojure handling source block variable's value is a org-mode table or list

2022-10-28 Thread Daniel Kraus


Bastien  writes:

> Daniel Kraus  writes:
>> I would set it to (and (executable-find "bb") 'babashka) so it's still nil
>> when babashka is installed?
> (You mean "not installed", right?)

Of course.

>> Or we could even test more available backends like
>>
>> (cond
>>  ((executable-find "bb") 'babashka)
>>  ((executable-find "nbb") 'nbb)
>>  ((featurep 'cider) 'cider)
>>  ((featurep 'inf-clojure) 'inf-clojure)
>>  ((featurep 'slime) 'slime))
>>
>> Or is that too much "magic" in that on some systems the default is bb
>> and in others it's cider etc?
>
> I think this is acceptable magic: perhaps we should first check what
> is done in other Babel languages and align with their level of magic
> for guessing the correct executable -- but I suspect Clojure is a bit
> special here, in that it has a lot of different options.

I looked around a bit but couldn't find another babel package with a
similar problems, i.e. that some backends are completely different
and not just changing the name of the executable.

I think I'll go with the big `cond` above to auto-detect what's
installed. That's probably the best out-of-the-box experience.

Cheers,
  Daniel



Re: [PATCH] Fix ob-clojure handling source block variable's value is a org-mode table or list

2022-10-28 Thread Bastien
Hi Daniel,

Daniel Kraus  writes:

> I would set it to (and (executable-find "bb") 'babashka) so it's still nil
> when babashka is installed?

(You mean "not installed", right?)

> Or we could even test more available backends like
>
> (cond
>  ((executable-find "bb") 'babashka)
>  ((executable-find "nbb") 'nbb)
>  ((featurep 'cider) 'cider)
>  ((featurep 'inf-clojure) 'inf-clojure)
>  ((featurep 'slime) 'slime))
>
> Or is that too much "magic" in that on some systems the default is bb
> and in others it's cider etc?

I think this is acceptable magic: perhaps we should first check what
is done in other Babel languages and align with their level of magic
for guessing the correct executable -- but I suspect Clojure is a bit
special here, in that it has a lot of different options.

Thanks for taking care of this,

-- 
 Bastien



Re: [PATCH] Fix ob-clojure handling source block variable's value is a org-mode table or list

2022-10-28 Thread Daniel Kraus
Hi!

Bastien Guerry  writes:
> For now `org-babel-clojure-backend' is nil.
>
> I suggest to set it to babashka by default: babashka is stable and
> well established now, it is by far the most efficient way to run
> Clojure code.  Also, it is particularily suitable for Babel use.
>
> What do you think?

Sounds good.
I would set it to (and (executable-find "bb") 'babashka) so it's still nil
when babashka is installed?

Or we could even test more available backends like

(cond
 ((executable-find "bb") 'babashka)
 ((executable-find "nbb") 'nbb)
 ((featurep 'cider) 'cider)
 ((featurep 'inf-clojure) 'inf-clojure)
 ((featurep 'slime) 'slime))

Or is that too much "magic" in that on some systems the default is bb
and in others it's cider etc?

Cheers,
  Daniel



Re: [PATCH] Fix ob-clojure handling source block variable's value is a org-mode table or list

2022-10-28 Thread Bastien Guerry
Hi Daniel,

Daniel Kraus  writes:

> 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.

For now `org-babel-clojure-backend' is nil.

I suggest to set it to babashka by default: babashka is stable and
well established now, it is by far the most efficient way to run
Clojure code.  Also, it is particularily suitable for Babel use.

What do you think?

-- 
 Bastien



Re: [PATCH] Fix ob-clojure handling source block variable's value is a org-mode table or list

2022-10-27 Thread Ihor Radchenko
Daniel Kraus  writes:

> 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.

Thanks!

> 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..)"

*is is

Otherwise, feel free to push.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: [PATCH] Fix ob-clojure handling source block variable's value is a org-mode table or list

2022-10-27 Thread Daniel Kraus
Hi!

Ihor Radchenko  writes:

> "Christopher M. Miles"  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
>From 1a2fa382e7a5925d4b85d90f1fe4ac7c012f81a4 Mon Sep 17 00:00:00 2001
From: Daniel Kraus 
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



Re: [PATCH] Fix ob-clojure handling source block variable's value is a org-mode table or list

2022-10-26 Thread Ihor Radchenko
"Christopher M. Miles"  writes:

> I bellowing example:
>
> #+begin_src org
> ,#+NAME: ob-clojure-table-test
> | a | b | c |
> |---+---+---|
> | 1 | 2 | 3 |
>
> ,#+NAME: ob-clojure-table-test-2
> | a | b | c |
> |---+---+---|
> | 1 | 2 | 3 |
>
> ,#+begin_src clojure :var kk=ob-clojure-table-test :var 
> kk2=ob-clojure-table-test-2 :results output
> (println kk2)
> (println kk)
> ,#+end_src
>
> #+end_src
>
> 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.

>;; 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?

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: [PATCH] Fix ob-clojure handling source block variable's value is a org-mode table or list

2022-09-18 Thread Christopher M. Miles

Ping Bastien Guerry.

"Christopher M. Miles"  writes:

> [[PGP Signed Part:Undecided]]
>
> I bellowing example:
>
> #+begin_src org
> ,#+NAME: ob-clojure-table-test
> | a | b | c |
> |---+---+---|
> | 1 | 2 | 3 |
>
> ,#+NAME: ob-clojure-table-test-2
> | a | b | c |
> |---+---+---|
> | 1 | 2 | 3 |
>
> ,#+begin_src clojure :var kk=ob-clojure-table-test :var 
> kk2=ob-clojure-table-test-2 :results output
> (println kk2)
> (println kk)
> ,#+end_src
>
> #+end_src
>
> Without this patch, it will report error "class java.lang.ClassCastException" 
> from CIDER.
>
> This patch added if condition to handle this table, list type data.
>
> From 948e8c1ff2c9ba1d9c0fe26f9bdaa096bef80a9d Mon Sep 17 00:00:00 2001
> From: stardiviner 
> Date: Sat, 9 Apr 2022 21:14:22 +0800
> Subject: [PATCH] ob-clojure.el: Fix header argument :var binding passed table
>  or list data
>
> * lisp/ob-clojure.el (org-babel-expand-body:clojure): Add if condition
> to handle source block :var passed org-mode table or list data for
> clojure let-binding to avoid java.lang.ClassCastException.
> ---
>  lisp/ob-clojure.el | 25 ++---
>  1 file changed, 18 insertions(+), 7 deletions(-)
>
> diff --git a/lisp/ob-clojure.el b/lisp/ob-clojure.el
> index 5a44b6487..e6614b2d9 100644
> --- a/lisp/ob-clojure.el
> +++ b/lisp/ob-clojure.el
> @@ -101,13 +101,24 @@
>(and (cdr (assq :ns params)) (format "(ns %s)\n" ns))
>;; 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)))
> +   (format "(let [%s]\n%s)"
> +   (mapconcat
> +(lambda (var)
> +  (format "%S '%S" (car var) (cadr var)))
> +vars
> +"\n  ")
> +   body)
> + ;; else, the header argument variable's value is not a 
> list.
> + (format "(let [%s]\n%s)"
> + (mapconcat
> +  (lambda (var)
> +(format "%S %S" (car var) (cdr var)))
> +  vars
> +  "\n  ")
> + body)
> + ))
>  (if (or (member "code" result-params)
>   (member "pp" result-params))
>   (format "(clojure.pprint/pprint (do %s))" body)
> -- 
> 2.35.1
>
> [5. text/x-patch; 
> 0001-ob-clojure.el-Fix-header-argument-var-binding-passed.patch]...


-- 

[ stardiviner ]
I try to make every word tell the meaning that I want to express without 
misunderstanding.

Blog: https://stardiviner.github.io/
IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3


signature.asc
Description: PGP signature


[PATCH] Fix ob-clojure handling source block variable's value is a org-mode table or list

2022-04-09 Thread Christopher M. Miles

I bellowing example:

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

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

,#+begin_src clojure :var kk=ob-clojure-table-test :var 
kk2=ob-clojure-table-test-2 :results output
(println kk2)
(println kk)
,#+end_src

#+end_src

Without this patch, it will report error "class java.lang.ClassCastException" 
from CIDER.

This patch added if condition to handle this table, list type data.

From 948e8c1ff2c9ba1d9c0fe26f9bdaa096bef80a9d Mon Sep 17 00:00:00 2001
From: stardiviner 
Date: Sat, 9 Apr 2022 21:14:22 +0800
Subject: [PATCH] ob-clojure.el: Fix header argument :var binding passed table
 or list data

* lisp/ob-clojure.el (org-babel-expand-body:clojure): Add if condition
to handle source block :var passed org-mode table or list data for
clojure let-binding to avoid java.lang.ClassCastException.
---
 lisp/ob-clojure.el | 25 ++---
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/lisp/ob-clojure.el b/lisp/ob-clojure.el
index 5a44b6487..e6614b2d9 100644
--- a/lisp/ob-clojure.el
+++ b/lisp/ob-clojure.el
@@ -101,13 +101,24 @@
 		 (and (cdr (assq :ns params)) (format "(ns %s)\n" ns))
 		 ;; 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)))
+   (format "(let [%s]\n%s)"
+   (mapconcat
+(lambda (var)
+  (format "%S '%S" (car var) (cadr var)))
+vars
+"\n  ")
+   body)
+ ;; else, the header argument variable's value is not a list.
+ (format "(let [%s]\n%s)"
+ (mapconcat
+  (lambda (var)
+(format "%S %S" (car var) (cdr var)))
+  vars
+  "\n  ")
+ body)
+ ))
 (if (or (member "code" result-params)
 	(member "pp" result-params))
 	(format "(clojure.pprint/pprint (do %s))" body)
-- 
2.35.1

From 948e8c1ff2c9ba1d9c0fe26f9bdaa096bef80a9d Mon Sep 17 00:00:00 2001
From: stardiviner 
Date: Sat, 9 Apr 2022 21:14:22 +0800
Subject: [PATCH] ob-clojure.el: Fix header argument :var binding passed table
 or list data

* lisp/ob-clojure.el (org-babel-expand-body:clojure): Add if condition
to handle source block :var passed org-mode table or list data for
clojure let-binding to avoid java.lang.ClassCastException.
---
 lisp/ob-clojure.el | 25 ++---
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/lisp/ob-clojure.el b/lisp/ob-clojure.el
index 5a44b6487..e6614b2d9 100644
--- a/lisp/ob-clojure.el
+++ b/lisp/ob-clojure.el
@@ -101,13 +101,24 @@
 		 (and (cdr (assq :ns params)) (format "(ns %s)\n" ns))
 		 ;; 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)))
+   (format "(let [%s]\n%s)"
+   (mapconcat
+(lambda (var)
+  (format "%S '%S" (car var) (cadr var)))
+vars
+"\n  ")
+   body)
+ ;; else, the header argument variable's value is not a list.
+ (format "(let [%s]\n%s)"
+ (mapconcat
+  (lambda (var)
+(format "%S %S" (car var) (cdr var)))
+  vars
+  "\n  ")
+ body)
+ ))
 (if (or (member "code" result-params)
 	(member "pp" result-params))
 	(format "(clojure.pprint/pprint (do %s))" body)
-- 
2.35.1


-- 
[ stardiviner ]
   I try to make every word tell the meaning that I want to express.

   Blog: https://stardiviner.github.io/
   IRC(freenode): stardiviner, Matrix: stardiviner
   GPG: F09F650D7D674819892591401B5DF1C95AE89AC3


signature.asc
Description: PGP signature