This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-10-12
Channels
- # announcements (13)
- # aws (18)
- # babashka (60)
- # babashka-sci-dev (83)
- # beginners (32)
- # biff (18)
- # calva (22)
- # cider (8)
- # clj-on-windows (101)
- # clojure (59)
- # clojure-bay-area (2)
- # clojure-europe (36)
- # clojure-india (4)
- # clojure-nl (3)
- # clojure-norway (5)
- # clojure-spec (4)
- # clojure-uk (1)
- # clojurescript (5)
- # conjure (1)
- # core-async (10)
- # cursive (7)
- # data-science (5)
- # datahike (10)
- # datalog (11)
- # datomic (3)
- # docker (3)
- # figwheel-main (2)
- # gratitude (3)
- # improve-getting-started (1)
- # introduce-yourself (5)
- # jobs (3)
- # joyride (12)
- # leiningen (1)
- # lsp (67)
- # malli (27)
- # off-topic (36)
- # random (1)
- # rdf (1)
- # re-frame (17)
- # reagent (21)
- # reitit (4)
- # releases (4)
- # remote-jobs (2)
- # ring (2)
- # sci (35)
- # shadow-cljs (28)
- # sql (3)
- # squint (9)
- # tools-deps (11)
Does using sci from cljs work the same way as from clj?
I'm trying to determine if it fits the requirements I have for a project where I need a tiny lisp interpreter.
More or less I need to be able to evaluate small lisp expressions with some custom functions injected, but I also need to be able to walk it after macroexpansion and find any usages of what's effectively a new special form prop
and extract that information before evaluation.
Is that reasonably within reach with sci?
To the best of my understanding, I think that should be possible. At least, I don't know of any reason why it's not possible. A specific example would help :) Here's the sci README on macros: https://github.com/babashka/sci#macros
Yeah, I was reading through this and I can see macros are supported, but I haven't been able to tell if there's any way to get the non-evaluated macroexpanded expression.
Which is a value I need
I don't see anything about macroexpanding in the api markdown file either
Is there any reason you can't submit the form as (clojure.walk/macroexpand-all (quote ~form))
to get what you need?
or even:
{:expanded (clojure.walk/macroexpand-all (quote ~form))
:result ~form}
So you mean like read in the expression, wrap it in a macroexpand all, quote it, and then eval that?
I guess I could potentially do that.
is that macroexpand all provided by sci?
I don't think I can provide it in cljs
I tried it in bb
I think this would need nbb
I'm not sure if that means it also applies to sci in cljs
I'll give it a shot a little later
I don't have nbb
handy, but should be easy to test
Yeah, I'll test it out. If that works, then I think I can use sci as-is. If not, then I might need to look at the inner workings and think about a PR to add a macroexpand to the API.
(require '[sci.core :as sci])
(let [ctx (sci/init {})]
(sci/eval-form ctx '(do (defmacro lol [y] y)
(def x 123)
{:x-stuff (* x (lol x))
:macro-stuff (macroexpand (quote (lol :abc)))})))
;; => {:x-stuff 15129, :macro-stuff :abc}
Something like this?Yeah, it's available from inside, my question was about doing macroexpand instead of eval-form
Which yeah, looks like can be done by just wrapping macroexpand and quote before evaling
(defn macroexpand-in-sci [code]
(let [ctx (sci/init {})]
(sci/eval-form ctx
`(macroexpand (quote ~code)))))
(macroexpand-in-sci '(when true
:abc))
;; => (if true (do :abc))
My issue here is I'm basically writing a bunch of tiny separate sci expressions which need to be able to refer to stuff that's provided outside of the sci context by way of this prop
special function but I have to be able to find usages of prop outside the context of sci
although putting some more thought into that I might even need to mess with that a little more because of the potential for constructing symbols at runtime to pass to prop
That's what I'd initially thought to do but I need to macroexpand first
This is just one tiny part of a very complex whole that I'm trying to work out a spec for and determine exactly what components need what features. ATM it's looking like sci can do what I need from an interpreter though.
ok, so you do first a macroexpand inside SCI, then walk that expression and then eval that expression in SCI :)

yup, that's the conclusion we came to! Glad that's confirmed to work. 🙂
It seems like I'd be able to do most of this, but I'm not quite sure with a separate macroexpand step