Fork me on GitHub
#sci
<
2020-10-27
>
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?

borkdude15:10:37

@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 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

borkdude15:10:51

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

borkdude15:10:14

yeah, it will save some map merges

borkdude15:10:23

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

borkdude15:10:53

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?

borkdude16:10:07

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

borkdude16:10:20

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 🙂

borkdude16:10:55

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 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

borkdude16:10:23

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!

borkdude16:10:24

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

borkdude16:10:26

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

Sam Ritchie16:10:07

looks like it made it up

borkdude16:10:27

heh, no, never mind, it worked

borkdude16:10:32

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

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

teodorlu18:10:05

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

borkdude18:10:53

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.

borkdude18:10:26

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

teodorlu18:10:08

OK. Thanks for the prompt response :thumbsup: