Hey all! had a Q for the group - if I already have a quoted form, is there a way to not roundtrip through string and gain some efficiency?
@sritchie09 Sci supports eval-form
. It is a lower level primitive.
user=> (require '[sci.core :as sci])
nil
user=> (def ctx (sci/init {}))
#'user/ctx
user=> (sci/eval-form ctx '(+ 1 2 3 ))
6
awesome!
thanks @borkdude
@borkdude do you recommend creating a new context for each eval
call, if I'm not attempting to persist state?
ie is there some efficiency gain to creating it once, even if I don't want to communicate info across eval calls
you can also use sci/init
+ sci/fork
. Fork will create a new ctx from the state of the ctx given
yeah, it will save some map merges
but maybe in a typical setting it won't matter that much
it depends, like, if you're doing 100s of evals per second, then it makes sense to pre-create the context once
the setting here is a scientific computing package, where I have
• some super nested physics functions written in terms of generic operations,
• I pass in 'x
and get back a big evaluation tree that I simplify,
• once everything's simplified I eval-form
once, then use the compiled function a bunch
so probably doesn't matter too much here, but it's easy to do
@borkdude eval-form
must be in the latest alpha yeah?
it might not have been published to clojars as an alpha. can do that, if you need it
as in, if you're not doing git libs
I'm currently still in leiningen land, and all of my build knowledge is rip-van-winkled in from 2015 🙂
ok, let me push an update
that would be awesome
I'll convert to deps.edn
soon, but this would be really helpful
@borkdude also THANK YOU for writing sci!!!!
I've been on this months-long push to get https://github.com/littleredcomputer/sicmutils converted to Clojurescript as part of my larger "dynamic notebooks" project, basically a lightweight mathematica-style interface in the browser, etc etc
I bumped it to 0.1.1-alpha.8
, should be there in a few minutes.
and the ability to simplify and live-compile functions down in a cljs browser environment is a hard requirement... I thought I'd be stuck in prototype land with a self-hosted-cljs requirement
excellent thank you!
cool, nice to hear sci comes in useful for this :)
@sritchie09 Hmm, deploy failed due to token I have to refresh. One minute
looks like it made it up
heh, no, never mind, it worked
@sritchie09 If you're adopting sci, feel free to list your project here as well: https://github.com/borkdude/sci#projects-using-sci
sg, will send a PR shortly
amazing... a differential equation simulation goes from 4 seconds to 80ms in clojurescript now that I can apply simplifications inside the function
Hello! Can I use :allow to whitelist what's allowed to do, but also let the arbitrary symbols be used in defs?
Hmm. Currently that doesn't work. The unqualified symbols in allow really mean clojure.core/+, clojure.core/def etc. It seems a bit silly that one is not able to def things this way. So maybe we should re-think this option a bit.
Feel free to post an issue about this possibly with some suggestions
OK. Thanks for the prompt response :thumbsup:
Thanks