Fork me on GitHub
#babashka
<
2024-01-11
>
Akiz09:01:38

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.

Akiz09:01:34

@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 '[ :as io] '[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..

borkdude09:01:46

You have to quote '[get-sheet]

Akiz09:01:53

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:

Akiz09:01:20

the block of code is valid, it works when i run it through shell..

borkdude10:01:30

o sorry, I misread, you don't have to quote the inner thing

😅 1
borkdude10:01:00

Perhaps you first have to eval the require separatel

borkdude10:01:07

before you can use the referred thing

Akiz10:01:15

i can imagine it has something to do with path…

borkdude10:01:16

I don't know how this org-mode thing works, I haven't written it

Akiz10:01:18

I tried it as well

Akiz10:01:35

Don’t worry, i can live with a shell workaround for now

Akiz10:01:14

i got the configuration right some time ago but i lost my init.el.. eh

borkdude10:01:32

Perhaps the venerable @U02CV2P4J6S knows

👍 1
Benjamin10:01:13

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

Akiz10:01:53

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

Akiz10:01:04

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

teodorlu14:01:12

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

Akiz13:01:49

I got no reply but I probably found the issue. Org wraps the script in this block. (prn (binding [*out* (.StringWriter.)] <CODE> )) 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.

borkdude13:01:24

Put the require in a separate org block

borkdude13:01:34

require does work, but you cannot use the alias in the same block

borkdude13:01:41

you can however use it in the next one

borkdude13:01:16

@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}

Akiz13:01:27

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

Akiz13:01:21

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!

borkdude13:01:30

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"]

Akiz13:01:05

Can you take a look at the generated clj file?

borkdude13:01:11

where is that?

Akiz13:01:08

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

borkdude13:01:44

are you using ob-clojure which is part of emacs?

Akiz13:01:33

Yes (org-babel-clojure-backend 'cider)

borkdude13:01:04

That's not what I'm using I think

borkdude13:01:14

that function isn't even defined in my emacs

borkdude13:01:52

I don't see what cider has to do with bb

Akiz13:01:14

Ah, nothing, i just forgot to copy the part where i require ob-clojure 🙂

borkdude13:01:27

I'm just pressing C-c to execute those code blocks and it either works or I don't see anything

borkdude13:01:32

are you doing something else?

borkdude13:01:40

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"]

borkdude13:01:39

oh yes, I see an error when I change something that is obviously an error, wait up

borkdude13:01:32

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)

borkdude13:01:36

no binding stuff in my case

Akiz13:01:38

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

borkdude13:01:22

> Org wraps the script in this block. > (prn (binding [*out* (.StringWriter.)] <CODE> ))

borkdude13:01:31

Perhaps I'm using a version where it doesn't do that?

borkdude13:01:04

I don't know how to check that, but it seems something is different in our setup

👍 1
Akiz13:01:34

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

borkdude13:01:15

That's not in my copy of ob-clojure, like I said, this is bundled with emacs itself

borkdude13:01:03

there is no binding expression in ob-clojure.el on this side

Akiz13:01:07

Ok, makes sense as i have updated org… I’ll try to sort it out and send a fix. Thanks for your assistance 🙂

borkdude13:01:56

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?

👍 1
Akiz13:01:44

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?

Akiz13:01:23

I’m going to switch

Akiz13:01:32

But it looks that straight.el is using bzg one by default, hm

borkdude13:01:57

why would you need straight.el for something that is built into emacs?

Akiz13:01:41

I want a newer version and I don’t use Elpa

borkdude13:01:54

I'll wait for @UFAP0C8KU - maybe he knows why the versions differ

👍 1
borkdude13:01:17

and after that I would suggest another workaround for the binding, possible that set! works better with require etc

borkdude13:01:55

aliases can only be used by successive top level forms. wrapping something in a binding doesn't make it a top level form

borkdude13:01:15

but you can also write it as:

(set! *out* ...)
... your expression ...
(set! *out* the-old-value)

borkdude13:01:42

however, the built-in version doesn't modify *out* at all, so I'd be curious what is the thinking behind this

Akiz13:01:25

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

Ryan18:01:37

Troubleshooting some task runner funnybusiness, any clues as to why (current-task) would be nil on entering task (via fn in :enter)

1
Ryan18:01:52

Might have found it, :enter and :leave ended up inside the init (do) by mistake! Maybe have fixed it

👍 1