This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-01-11
Channels
- # announcements (1)
- # babashka (70)
- # beginners (8)
- # calva (5)
- # cider (9)
- # clojure (48)
- # clojure-austin (68)
- # clojure-europe (29)
- # clojure-norway (30)
- # clojure-uk (5)
- # clojuredesign-podcast (2)
- # cursive (19)
- # datomic (10)
- # emacs (11)
- # events (2)
- # exercism (4)
- # fulcro (2)
- # hyperfiddle (29)
- # introduce-yourself (2)
- # jobs-discuss (4)
- # kaocha (1)
- # leiningen (8)
- # lsp (8)
- # malli (2)
- # matcher-combinators (20)
- # nrepl (15)
- # off-topic (33)
- # reagent (7)
- # releases (4)
- # shadow-cljs (42)
- # spacemacs (6)
- # sql (6)
- # squint (10)
- # vim (3)
Hi, does anyone use org mode with BB? What is your approach?
When I use
1. #+begin_src clojure :backend babashka
then i have a problem with libraries installed by deps/add-deps
, I can’t require them.
2. #+begin_src shell :shebang "#!/usr/bin/env bb"
Works but I lose the syntax higlighting in org blocks.
Here's something: https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-clojure.html search the page for babashka
@U04V15CAJ This is what I have tried as a first step.
For some reason, it can’t find dependencies.
This
(require '[babashka.deps :as deps])
(deps/add-deps
'{:deps {com.github.kbosompem/bb-excel {:mvn/version "0.0.9"}}})
(require '[
'[clojure.pprint :refer [print-table pprint]]
'[bb-excel.core :as bc :refer [get-sheet get-sheets]])
(get-sheet "test/data/simple.xlsx" "Shows")
fails with
----- Error --------------------------------------------------------------------
Type: clojure.lang.ExceptionInfo
Message: Could not resolve symbol: get-sheet
Data: {:type :sci/error, :line 1, :column 1, :file "/var/folders/wd/74d3rstj7xjbs9zhtdp3vxyh0000gn/T/babel-LnPnWx/clojure-cmd-script-PW9TkF.clj", :phase "analysis"}
Location: /var/folders/wd/74d3rstj7xjbs9zhtdp3vxyh0000gn/T/babel-LnPnWx/clojure-cmd-script-PW9TkF.clj:8:1
Phase: analysis
----- Context ------------------------------------------------------------------
4: (require '[ :as io]
5: '[clojure.pprint :refer [print-table pprint]]
6: '[bb-excel.core :as bc :refer [get-sheet get-sheets]])
7:
8: (get-sheet "test/data/simple.xlsx" "Shows" )
^--- Could not resolve symbol: get-sheet
9: (get-sheet (io/file "test/data/simple.xlsx") 1)))
It wraps the code in
(prn (binding [*out* (.StringWriter.)] …
But i don’t see how it can be related to the error.
Will be something else probably..You mean like this
(require '[ :as io]
'[clojure.pprint :refer [print-table pprint]]
'[bb-excel.core :as bc :refer '[get-sheet get-sheets]])
:thinking_face:Yea I know that somebody in #C099W16KZ will know 😛 Maybe something is dropping the first req form and it would be fixed if everything is in a do
? Or the difference comes from the current directory bb is invoked with
@U02CV2P4J6S I have tried that as well (wraping it in do), no luck. I will try to find some time to debug it further then.
but if there is somebody on linux who can try it so i know if it is caused by OS (path) or not would be helpful 🙂.
> Yea I know that somebody in #C099W16KZ will know 😛 I recommend asking in #C099W16KZ too, there’s some really deep Emacs knowledge lurking in that channel!
I got no reply but I probably found the issue.
Org wraps the script in this block.
(prn (binding [*out* (
And for some reason - requiring doesn’t work inside this (even if i eval it outside of Emacs).
I didn’t know it.
I am not sure what the best solution is.
@UBRV1HXPD Btw this works fine on my system:
#+begin_src clojure :backend babashka
(prn (+ 1 2 3))
#+end_src
#+RESULTS:
: 6
#+begin_src clojure :backend babashka
(require '[clojure.set :as set2])
(prn (set2/union #{1 2 3} #{4 5 6}))
#+end_src
#+RESULTS:
: #{1 4 6 3 2 5}
----- Error --------------------------------------------------------------------
Type: clojure.lang.ExceptionInfo
Message: Could not resolve symbol: set2/union
Data: {:type :sci/error, :line 1, :column 1, :file "/var/folders/wd/74d3rstj7xjbs9zhtdp3vxyh0000gn/T/babel-L7yEP7/clojure-cmd-script-cQUnZp.clj", :phase "analysis"}
Location: /var/folders/wd/74d3rstj7xjbs9zhtdp3vxyh0000gn/T/babel-L7yEP7/clojure-cmd-script-cQUnZp.clj:2:6
Phase: analysis
----- Context ------------------------------------------------------------------
1: (prn (binding [*out* (java.io.StringWriter.)](require '[clojure.set :as set2])
2: (prn (set2/union #{1 2 3} #{4 5 6}))))
^--- Could not resolve symbol: set2/union
----- Stack trace --------------------------------------------------------------
Interestingly, I am not able to achieve what I need even with the help of more org blocks. But obviously there is something wrong on my side, thank you very much!
This also works for me:
#+begin_src clojure :backend babashka
(require '[babashka.deps :as deps])
(deps/add-deps
'{:deps {com.github.kbosompem/bb-excel {:mvn/version "0.0.9"}}})
(require '[ :as io]
'[clojure.pprint :refer [print-table pprint]]
'[bb-excel.core :as bc :refer [get-sheet get-sheets]])
(prn get-sheet)
#+end_src
#+RESULTS:
: #object[sci.impl.analyzer$analyze_fn_STAR_$reify__4198$f__4199 0x64c5af3f "sci.impl.analyzer$analyze_fn_STAR_$reify__4198$f__4199@64c5af3f"]
I see the path in the Babel error output 😅. But it look like this /var/folders/wd/74d3rstj7xjbs9zhtdp3vxyh0000gn/T/babel-L7yEP7/clojure-cmd-script-9NYx0z.clj.. And this is what i see in the file:
(prn (binding [*out* (java.io.StringWriter.)](require '[clojure.set :as set2])
(prn (set2/union #{1 2 3} #{4 5 6}))))
and when i eval this file as :
akiz@Jakubs-MacBook-Pro ~ % bb /private/var/folders/wd/74d3rstj7xjbs9zhtdp3vxyh0000gn/T/babel-L7yEP7/clojure-cmd-script-9NYx0z.clj
----- Error --------------------------------------------------------------------
Type: clojure.lang.ExceptionInfo
Message: Could not resolve symbol: set2/union
Data: {:type :sci/error, :line 1, :column 1, :file "/private/var/folders/wd/74d3rstj7xjbs9zhtdp3vxyh0000gn/T/babel-L7yEP7/clojure-cmd-script-9NYx0z.clj", :phase "analysis"}
Location: /private/var/folders/wd/74d3rstj7xjbs9zhtdp3vxyh0000gn/T/babel-L7yEP7/clojure-cmd-script-9NYx0z.clj:2:6
Phase: analysis
----- Context ------------------------------------------------------------------
1: (prn (binding [*out* (java.io.StringWriter.)](require '[clojure.set :as set2])
2: (prn (set2/union #{1 2 3} #{4 5 6}))))
^--- Could not resolve symbol: set2/union
----- Stack trace --------------------------------------------------------------
user - /private/var/folders/wd/74d3rstj7xjbs9zhtdp3vxyh0000gn/T/babel-L7yEP7/clojure-cmd-script-9NYx0z.clj:2:6
clojure.core/prn - <built-in>
user/let - /private/var/folders/wd/74d3rstj7xjbs9zhtdp3vxyh0000gn/T/babel-L7yEP7/clojure-cmd-script-9NYx0z.clj:2:1
user - /private/var/folders/wd/74d3rstj7xjbs9zhtdp3vxyh0000gn/T/babel-L7yEP7/clojure-cmd-script-9NYx0z.clj:1:6
clojure.core/let - <built-in>
... (run with --debug to see elided elements)
clojure.core/binding - <built-in>
user/prn - /private/var/folders/wd/74d3rstj7xjbs9zhtdp3vxyh0000gn/T/babel-L7yEP7/clojure-cmd-script-9NYx0z.clj:1:6
user - /private/var/folders/wd/74d3rstj7xjbs9zhtdp3vxyh0000gn/T/babel-L7yEP7/clojure-cmd-script-9NYx0z.clj:1:6
clojure.core/prn - <built-in>
user - /private/var/folders/wd/74d3rstj7xjbs9zhtdp3vxyh0000gn/T/babel-L7yEP7/clojure-cmd-script-9NYx0z.clj:1:1
It is from here.. https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-clojure.html
I'm just pressing C-c to execute those code blocks and it either works or I don't see anything
This is my entire file now:
#+begin_src clojure :backend babashka
(prn (+ 1 2 3))
#+end_src
#+RESULTS:
: 6
#+begin_src clojure :backend babashka
(require '[clojure.set :as set2])
(prn (set2/union #{1 2 3} #{4 5 6}))
#+end_src
#+RESULTS:
: #{1 4 6 3 2 5}
#+begin_src clojure :backend babashka
(require '[babashka.deps :as deps])
(deps/add-deps
'{:deps {com.github.kbosompem/bb-excel {:mvn/version "0.0.9"}}})
(require '[ :as io]
'[clojure.pprint :refer [print-table pprint]]
'[bb-excel.core :as bc :refer [get-sheet get-sheets]])
(prn get-sheet)
#+end_src
#+RESULTS:
: #object[sci.impl.analyzer$analyze_fn_STAR_$reify__4198$f__4199 0x64c5af3f "sci.impl.analyzer$analyze_fn_STAR_$reify__4198$f__4199@64c5af3f"]
This is what it generates for the last block:
(require '[babashka.deps :as deps])
(deps/add-deps
'{:deps {com.github.kbosompem/bb-excel {:mvn/version "0.0.9"}}})
(require '[ :as io]
'[clojure.pprint :refer [print-table pprint]]
'[bb-excel.core :as bc :refer [get-sheet get-sheets]])
(prn xget-sheet)
I am just looking into ob-clojure.el, it looks that it is doing what it should. But when i take the produced code and run it via bb, it fails once there is a require..
> Org wraps the script in this block.
> (prn (binding [*out* (
2023-03-16, not so new…
If you use straight.el, you can take a look into
.emacs.d/straight/repos/org/lisp/ob-clojure.el
Ok, makes sense as i have updated org… I’ll try to sort it out and send a fix. Thanks for your assistance 🙂
I also don't see that expression here https://github.com/emacs-mirror/emacs/blob/master/lisp/org/ob-clojure.el
I do see it here: https://github.com/bzg/org-mode/blob/9183e3c723b812360d1042196416d521db590e9f/lisp/ob-clojure.el#L191 apparently these things are different implementations with the same name?
Wow, I don’t know how but I am using this one https://github.com/bzg/org-mode So is it “patched” org, not mirror only?
and after that I would suggest another workaround for the binding
, possible that set!
works better with require etc
aliases can only be used by successive top level forms. wrapping something in a binding doesn't make it a top level form
but you can also write it as:
(set! *out* ...)
... your expression ...
(set! *out* the-old-value)
however, the built-in version doesn't modify *out*
at all, so I'd be curious what is the thinking behind this
btw. If I set code-block t o`:results output`, it works and skips the new code. That partially solves my problem, but I’m curious too..