sci

https://github.com/babashka/SCI - also see #babashka and #nbb
Sam Ritchie 2020-10-27T15:32:15.026300Z

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?

borkdude 2020-10-27T15:53:37.027100Z

@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

Sam Ritchie 2020-10-27T15:54:22.027700Z

awesome!

Sam Ritchie 2020-10-27T15:54:26.027900Z

thanks @borkdude

Sam Ritchie 2020-10-27T15:56:11.028400Z

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

Sam Ritchie 2020-10-27T15:56:39.029100Z

ie is there some efficiency gain to creating it once, even if I don't want to communicate info across eval calls

borkdude 2020-10-27T15:56:51.029400Z

you can also use sci/init + sci/fork. Fork will create a new ctx from the state of the ctx given

borkdude 2020-10-27T15:57:14.029800Z

yeah, it will save some map merges

borkdude 2020-10-27T15:57:23.030100Z

but maybe in a typical setting it won't matter that much

borkdude 2020-10-27T15:57:53.031100Z

it depends, like, if you're doing 100s of evals per second, then it makes sense to pre-create the context once

Sam Ritchie 2020-10-27T15:59:14.032600Z

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 Ritchie 2020-10-27T15:59:28.033Z

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

Sam Ritchie 2020-10-27T15:59:41.033400Z

@borkdude eval-form must be in the latest alpha yeah?

borkdude 2020-10-27T16:00:07.034Z

it might not have been published to clojars as an alpha. can do that, if you need it

borkdude 2020-10-27T16:00:20.034200Z

as in, if you're not doing git libs

Sam Ritchie 2020-10-27T16:00:49.034700Z

I'm currently still in leiningen land, and all of my build knowledge is rip-van-winkled in from 2015 🙂

borkdude 2020-10-27T16:00:55.035Z

ok, let me push an update

Sam Ritchie 2020-10-27T16:00:59.035200Z

that would be awesome

Sam Ritchie 2020-10-27T16:01:07.035500Z

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

Sam Ritchie 2020-10-27T16:01:20.035800Z

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

Sam Ritchie 2020-10-27T16:02:27.037300Z

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

borkdude 2020-10-27T16:03:23.038400Z

I bumped it to 0.1.1-alpha.8, should be there in a few minutes.

Sam Ritchie 2020-10-27T16:03:48.038900Z

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 Ritchie 2020-10-27T16:03:51.039100Z

excellent thank you!

borkdude 2020-10-27T16:04:24.039400Z

cool, nice to hear sci comes in useful for this :)

borkdude 2020-10-27T16:11:26.039800Z

@sritchie09 Hmm, deploy failed due to token I have to refresh. One minute

Sam Ritchie 2020-10-27T16:12:07.040100Z

looks like it made it up

borkdude 2020-10-27T16:12:27.040300Z

heh, no, never mind, it worked

borkdude 2020-10-27T16:16:32.040900Z

@sritchie09 If you're adopting sci, feel free to list your project here as well: https://github.com/borkdude/sci#projects-using-sci

Sam Ritchie 2020-10-27T16:17:04.041300Z

sg, will send a PR shortly

Sam Ritchie 2020-10-27T17:08:20.041600Z

https://github.com/borkdude/sci/pull/433

Sam Ritchie 2020-10-27T17:09:12.042800Z

amazing... a differential equation simulation goes from 4 seconds to 80ms in clojurescript now that I can apply simplifications inside the function

teodorlu 2020-10-27T18:27:05.043200Z

Hello! Can I use :allow to whitelist what's allowed to do, but also let the arbitrary symbols be used in defs?

borkdude 2020-10-27T18:32:53.043500Z

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.

borkdude 2020-10-27T18:33:26.043700Z

Feel free to post an issue about this possibly with some suggestions

teodorlu 2020-10-27T18:35:08.043900Z

OK. Thanks for the prompt response :thumbsup:

teodorlu 2020-10-27T19:14:54.044100Z

Issue: https://github.com/borkdude/sci/issues/434

borkdude 2020-10-27T20:48:54.044400Z

Thanks