This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-01-22
Channels
- # announcements (5)
- # aws (38)
- # aws-lambda (21)
- # babashka (45)
- # beginners (87)
- # boot (1)
- # calva (32)
- # cider (23)
- # clara (7)
- # clj-kondo (41)
- # cljs-dev (29)
- # clojure (145)
- # clojure-europe (6)
- # clojure-italy (12)
- # clojure-nl (4)
- # clojure-spec (39)
- # clojure-uk (45)
- # clojurescript (171)
- # copenhagen-clojurians (4)
- # cursive (14)
- # datomic (48)
- # docker (6)
- # figwheel-main (2)
- # fulcro (54)
- # jackdaw (1)
- # jobs (1)
- # kaocha (3)
- # leiningen (7)
- # luminus (6)
- # malli (2)
- # off-topic (51)
- # pathom (8)
- # quil (20)
- # re-frame (14)
- # reagent (1)
- # reitit (2)
- # remote-jobs (1)
- # shadow-cljs (39)
- # tools-deps (1)
- # vim (12)
- # xtdb (5)
I'm thinking of using https://github.com/borkdude/sci in AWS Lambda to have Clojure there as well (I'm writing javascript as we speak..). Has anyone done/thought about this?
@jeroenvandijk It is possible. Any reason you're not just using CLJS?
I've explained it here: https://clojurians.slack.com/archives/C1AL322AJ/p1579684099024600 TLDR; I want to use it in inline in my Cloudformation Templates
I guess I could use a CLJS layer as well and use eval. The work to set this up for me would be pretty similar. Maybe sci is easier to work with. I could try both actually
yep, that made me think about it 🙂
I'm trying to create an easy aws lambda environment now to test things
Another advantage of using sci of cljs would be that you can test (parts) in a jvm environment. node is not an environment something I feel super comfortable in, could be just me
I'm getting an error when trying the example in sci's README in node https://gist.github.com/jeroenvandijk/a15fa236ff86ad7b4cfa924c24aec1ba I don't really know what I'm doing. Seems to be a specific issue with dotimes
@jeroenvandijk Let me release a new version of sci for npm
Thank you!
@jeroenvandijk seems to work now
I'm about to release a 0.0.12 version before I embark on a journey to add multimethods...
jep works now! Thanks
> I'm about to release a 0.0.12 version before I embark on a journey to add multimethods... Exciting and challenging I suppose :)
This is pretty cool (updated the gist) https://gist.github.com/jeroenvandijk/a15fa236ff86ad7b4cfa924c24aec1ba
Do you know if there is something special regarding methods on objects?
(println (.toString "somethign to string"))
Gives
Error: Method toString on function String() { [native code] } not allowed! [at line , column ]
at new yl (/Users/jeroen/Projects/Private/github/node_modules/@borkdude/sci/sci.js:670:76)
at Function.zl.c (/Users/jeroen/Projects/Private/github/node_modules/@borkdude/sci/sci.js:672:71)
at Func
Should I do something special to make this work?@jeroenvandijk The interop part of sci for JS is probably not as complete as the JVM, simply because no-one needed this yet. For this example I solved that by just bringing in functions that do the interop: https://github.com/borkdude/sci-wallpaper-downloader/blob/master/main.js
ah thanks, good to know
@jeroenvandijk I pushed one commit to sci. This now is one step closer:
const { evalString } = require('@borkdude/sci');
const opts = {bindings: {f: function() { console.log('hello'); }},
classes: {String: String}};
evalString("(f (.toString \"foo\"))", opts);
It just needs an implementation for https://github.com/borkdude/sci/blob/a7212aae5b6c98886ff030e98b5d8327b4ac66a5/src/sci/impl/interop.cljc#L26
which I could not figure out yet.
You can build the npm library by executing script/compile-js
and then e.g.:
cp out/min/sci.min.js /tmp/sci/node_modules/@borkdude/sci/sci.js
Thanks! I'll play with it
Pushed another commit. The static function call now seems to work:
const { evalString } = require('@borkdude/sci');
const opts = {bindings: {f: function(...args) { console.log(args.join(' ')); }},
classes: {String: String}};
evalString("(f(String/fromCharCode 67))", opts);
prints:
C
That's quick. I can confirm the above works after pulling
@jeroenvandijk Pushed another thing. This now also works: evalString("(f(.charCodeAt \"foo\" 0))", opts);
I'm not sure if this works for every instance method call out there. I've tried something like this before, and then there was some problem I can't remember off the top of my head
Yes cool works as well
I'm guessing (.toString "s")
is a special case. In the browser console "s".toString()
does work
it says
Error: String.prototype.toString requires that 'this' be a String [at line 5, column 16]
maybe it would be cool if we could do:
const fs = require('fs');
const opts = {namespaces {fs fs}};
and then (:require [fs]) (fs/readFilesync ...)
Yeah would be cool
My flow for node scripts is a bit painful running node myscript.js
everytime. I'm wondering if it is not possible to load all the javascript files into Rhino (or another vm) and run javascript from the repl. I'll look into that later 🙈
oh funny, it seems this already works:
const fs = require('fs');
const opts = {bindings: {f: function(...args) { console.log('x', args.join(' ')); }},
namespaces: {fs: fs}};
console.log(evalString("(str (fs/readFileSync \"sci.js\"))", opts));
a bit weird, but this also seems to work:
const { evalString } = require('@borkdude/sci');
const fs = require('fs');
const opts = {namespaces: {
console: console,
fs: fs}};
evalString("(console/log (str (fs/readFileSync \"sci.js\")))", opts);