Fork me on GitHub
#babashka
<
2023-11-10
>
littleli14:11:33

Well deserved. The most approachable lisp interpreter in the solar system!

5
borkdude15:11:02

lol, really? and how many stars does c# have? (I couldn't find the repo)

isak16:11:08

https://github.com/dotnet/roslyn 18k, Though I see aspnetcore has 33k

Noah Bogart16:11:29

is there any chance of implementing deftype?

1
Noah Bogart16:11:55

maybe this is a question better suited for #C015LCR9MHD?

borkdude16:11:53

there is deftype, it's just more limited than with clj

Noah Bogart16:11:36

maybe https://book.babashka.org/#differences-with-clojure should be updated to make mention of the differences? is there documentation about the differences?

borkdude16:11:54

that is the documentation, but it could be stale

Noah Bogart16:11:16

it just says "no deftype", sorry

Noah Bogart16:11:29

maybe i'm misusing it in my app

borkdude16:11:02

yes, as I said, the docs could be stale. deftype exists because of compatibility with existing libraries but it's better to just avoid it when you can

👍 1
borkdude16:11:37

just try it out

borkdude16:11:14

Babashka v1.3.186-SNAPSHOT REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.

user=> (deftype Foo [])
user.Foo
user=> (->Foo)
#object[user.Foo 0x4065989e "user.Foo@4065989e"]

Noah Bogart16:11:39

okay, i must be messing something up. thanks

borkdude16:11:45

if you have a repro, I would be able to explain why it would work in bb or not. if you're trying to implement clj interfaces on deftype, you're in bad luck

borkdude16:11:02

user-defined protocols do work

Noah Bogart16:11:02

well, it turns out whatever i'm doing also doesn't work in clojure (tho it's working in the repl), so i'm not sure what i'm doing wrong

Noah Bogart16:11:03

thanks for the help

👍 1
Ingy döt Net18:11:17

re the binary cat which bb` my-uberjar.jar` trick (which is reportedly the same as bb --jar my-uberjar.jar) I tried this with the uberjar I've been using with graalvm to make my ys command, and I get:

$ bb --jar target/uberjar/yamlscript.cli-0.1.0-SNAPSHOT-standalone.jar 
----- Error --------------------------------------------------------------------
Type:     clojure.lang.ExceptionInfo
Message:  Could not resolve symbol: pprint/write-option-table
Data:     {:type :sci/error, :line 12, :column 1, :file "a0/patch_pprint.clj", :phase "analysis"}
Location: a0/patch_pprint.clj:13:19
Phase:    analysis

----- Context ------------------------------------------------------------------
 9: 
10: (defonce patched? (volatile! false))
11: 
12: (when-not @patched?
13:   (alter-var-root #'pprint/write-option-table
                      ^--- Could not resolve symbol: pprint/write-option-table
14:     (fn [m]
15:       (zipmap (keys m)
16:         (map find-var (vals m))))))
17: 
18: (def new-table-ize

----- Stack trace --------------------------------------------------------------
a0.patch-pprint             - a0/patch_pprint.clj:13:19
clojure.core/alter-var-root - 
a0.patch-pprint/when-not    - a0/patch_pprint.clj:13:3
a0.patch-pprint             - a0/patch_pprint.clj:12:1
clojure.core/when-not       - 
a0.patch-pprint             - a0/patch_pprint.clj:12:1
a0.patch-pprint             - a0/patch_pprint.clj:12:1
yamlscript.core             - yamlscript/core.clj:13:3
yamlscript.cli              - yamlscript/cli.clj:9:3
user                        - :1:10
the a0/patch_pprint.clj thing is a trick that @borkdude helped me craft to massively reduce the size of my final binary file (`ys`)

borkdude18:11:46

@U05H8N9V0HZ you are trying to run your entire project through SCI this way. the pprint/write-option-table var isn't exposed in bb (SCI) since it's a private var

borkdude18:11:06

you could just remove that bit when you're in bb, which is done as follows:

(defmacro if-bb [then else]
  (if (System/getProperty "babashka.version")
    then else))
(if-bb nil ....)

Ingy döt Net18:11:30

ok, I was just following the https://github.com/babashka/babashka/wiki/Self-contained-executable#uberjar instructions to put bb in front of an uberjar with a -main

Ingy döt Net18:11:04

I'll try that, thanks. I guess this is a rather odd case for an uberjar

borkdude18:11:24

your mental model should be that the code in the jar file is a babashka-compatible project

borkdude18:11:31

it's not magically going to work for any Clojure project

borkdude18:11:35

it is already clarified:

This is effectively the same as running ./bb --jar uber.jar but all within one self-contained-binary.

Ingy döt Net18:11:51

From my pov, I went to this page because I heard you could turn an uberjar into a binary executable. I had an uberjar and followed the instructions and it failed.

Ingy döt Net18:11:16

maybe "Given an uberjar uber.jar that works with bb, ..."

borkdude18:11:25

What do you think happens when you run ./bb --jar uber.jar?

borkdude18:11:02

Also there is a reference to https://book.babashka.org/#_uberjar which shows how to build uberjars from your _bb_ program

borkdude18:11:17

But as it's a wiki, feel free to add whatever you need to see there

1
Ingy döt Net18:11:28

I get what you are saying, but you are assuming my mental model

borkdude18:11:59

thanks!

👍 1