This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-03-28
Channels
- # announcements (3)
- # babashka (36)
- # beginners (77)
- # boot (3)
- # chlorine-clover (10)
- # cider (27)
- # clj-kondo (1)
- # cljs-dev (4)
- # clojure (256)
- # clojure-belgium (1)
- # clojure-europe (9)
- # clojure-uk (18)
- # clojuredesign-podcast (9)
- # clojurescript (54)
- # cryogen (8)
- # cursive (3)
- # data-science (1)
- # datomic (2)
- # duct (31)
- # events (1)
- # exercism (3)
- # fulcro (116)
- # joker (20)
- # kaocha (5)
- # meander (2)
- # nrepl (4)
- # off-topic (10)
- # other-languages (15)
- # re-frame (18)
- # reagent (4)
- # shadow-cljs (44)
- # sql (14)
- # tools-deps (17)
I’m curious about using babashka/sci to implement a graalvm command line tool based around a library of mine that uses core.logic.
Unfortunately core.logic leverages a lot of JVM tricks etc to make it fast — e.g. protocols / definterface etc… Additionally core.logic programs tend to use macros such as fresh
/ run
etc.
I get the feeling this might be a bit beyond sci etc at the minute; and that I might be better creating a sci compatible port of miinkanren, and re-targeting my library on top of that?
@rickmoynihan it doesn't matter if core.logic itself uses defprotocol, etc. you can still hook it up to sci
the use case for sci is: you want to make a tool which exposes a Clojure DSL to its users. if that's not important, you can also just build your own graalvm tool
the Clojure DSL itself cannot use defprotocols, but you can access functions which use protocols behind the scenes
Yeah was thinking that I’d need to do that
Does sci support macros though? The DSL I’d like to expose is quite macro heavy at the minute.
the user can define macros themselves, but you can also hook in macros from the outside
ok you seem to be confirming what I was hoping then, so I’ll need to: 1. create a new clojure cli app that requires my dsl lib & sci 2. build it with graal 3. Hook my libs macros into sci 4. pass dsl forms into sci 5. profit
Thanks for confirming all this for me
A small note taking app in babashka: https://github.com/borkdude/babashka/#note-taking-app
If I have an existing defmacro
what’s the best way to expose it through sci?
The example in the README, seems to be for the macro body itself:
(def do-twice ^:sci/macro (fn [_&form _&env x] (list 'do x x)))
Is it for example possible to reuse something like clojure.core/when
and expose it as mywhen
?
hmm I guess I can do something like: (@#'clojure.core/when nil nil true '(println "hello"))
Ok this works:
(def mywhen ^:sci/macro (fn [form env test body] (@#'clojure.core/when form env test body)))
(sci/eval-string "(mywhen true (println \"hello\"))" {:bindings {'mywhen mywhen 'println println}})
Would it be worth adding an example like this to the README?A macro could build these def proxies easily enough — though I wonder if it might be better to just alter-meta!
on the macro vars adding the ^:sci/macro
metadata that way… :thinking_face:
trying it now…
@rickmoynihan the (def mywhen ^:sci/macro (fn [form env test body] (@#'clojure.core/when form env test body)))
approach works, but in general passing existing macros to sci breaks pretty fast, because the symbols in the macro body are resolved against a different namespace than inside sci
Yeah I was planing on requiring them in my ns too
sci.impl.main=> (def mywhen ^:sci/macro (fn [form env test body] (@#'clojure.core/when form env test body)))
#'sci.impl.main/mywhen
sci.impl.main=> (sci/eval-string "(mywhen true (+ 1 2 3))" {:bindings {'mywhen mywhen}})
6
sci.impl.main=> (sci/eval-string "(mywhen false (+ 1 2 3))" {:bindings {'mywhen mywhen}})
nil
yeah that’s pretty much exactly what I had
ahh yeah yours is a bit more minimal in bindings
bindings is just shorthand for {:namespaces {'user ...}}
- it stems from the time when there were no namespaces yet
yeah makes total sense
bindings and env in lisp interpreters are essentially the same thing right?
Added basic-auth and session management to the note app example 🙂 https://github.com/borkdude/babashka/#note-taking-app