Fork me on GitHub
Sam Ritchie15:10:15

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])
user=> (def ctx (sci/init {}))
user=> (sci/eval-form ctx '(+ 1 2 3 ))

Sam Ritchie15:10:11

@borkdude do you recommend creating a new context for each eval call, if I'm not attempting to persist state?

Sam Ritchie15:10:39

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

Sam Ritchie15:10:14

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

Sam Ritchie15:10:28

so probably doesn't matter too much here, but it's easy to do

Sam Ritchie15:10:41

@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

Sam Ritchie16:10:49

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

Sam Ritchie16:10:59

that would be awesome

Sam Ritchie16:10:07

I'll convert to deps.edn soon, but this would be really helpful

Sam Ritchie16:10:20

@borkdude also THANK YOU for writing sci!!!!

Sam Ritchie16:10:27

I've been on this months-long push to get 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.

Sam Ritchie16:10:48

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

Sam Ritchie16:10:51

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

Sam Ritchie16:10:07

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:

Sam Ritchie16:10:04

sg, will send a PR shortly

Sam Ritchie17:10:12

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: