This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-03-13
Channels
- # aleph (16)
- # announcements (8)
- # aws (5)
- # babashka (54)
- # beginners (48)
- # calva (7)
- # cider (7)
- # clojure (209)
- # clojure-brasil (4)
- # clojure-europe (20)
- # clojure-italy (12)
- # clojure-nl (21)
- # clojure-uk (69)
- # clojurescript (24)
- # cursive (11)
- # datascript (7)
- # datomic (47)
- # emacs (14)
- # graphql (20)
- # hoplon (25)
- # jobs (1)
- # kaocha (1)
- # leiningen (14)
- # meander (7)
- # off-topic (44)
- # other-languages (1)
- # pathom (20)
- # re-frame (2)
- # reagent (51)
- # reitit (3)
- # remote-jobs (1)
- # shadow-cljs (46)
- # spacemacs (5)
- # sql (65)
- # tools-deps (86)
- # vim (11)
user=> (.println *err* "test")
No matching method println found taking 1 args for class .PrintWriter [at line 22, column 1]
user=> (class "test")
java.lang.String
https://docs.oracle.com/javase/7/docs/api/java/io/PrintWriter.html#println(java.lang.String)
@skuro I've only included the constructor of PrintWriter for interop: https://github.com/borkdude/babashka/blob/7dc1fab97698ab80d53351a8b4d7f3149790feee/src/babashka/impl/classes.clj#L103 just to save some space 😉
using binding
seemed what most people were doing anyway so I didn't suspect this was needed
if you want I can bump PrintWriter to https://github.com/borkdude/babashka/blob/7dc1fab97698ab80d53351a8b4d7f3149790feee/src/babashka/impl/classes.clj#L16
Is there something im doing wrong here to call methods on js classes? 😅
(sci/eval-string "(.toUpperCase \"a\")"
{:classes {'String js/String}})
;;=? "FUNCTION TOUPPERCASE() { [NATIVE CODE] }"
hah. I think that's a bug in the sci JS interop. it might be nice to fix, but I think @jeroenvandijk was also working on this.
this works though:
cljs.user=> (sci/eval-string "(to-upper-case \"a\")" {:bindings {'to-upper-case #(.toUpperCase %)}})
"A"
@jeroenvandijk did you have a fix for the above issue?
@jjttjj the JS interop now looks like this:
(if (identical? \- (.charAt method-name 0))
(aget obj (subs method-name 1))
(if-let [method (aget obj method-name)]
(apply method obj args)
(throw (js/Error. (str "Could not find method: " method-name)))))
there are two PRs here, but I lost track of what kind of work was happening in which: https://github.com/borkdude/sci/pulls
Here's another quick possible bug in cljs:
(sci/eval-string "(println 23)(println 55)" {'println println})
;;=>
Error: cljs.core.deref(...).append is not a function [at line 1, column 1]
at new cljs$core$ExceptionInfo (/js/cljs-runtime/cljs.core.js:37203:10)
at Function.eval [as cljs$core$IFn$_invoke$arity$3] (/js/cljs-runtime/cljs.c...
that one is kind of expected, because by default sci does not allow println by binding *out*
to nothing
is there any way to have a function outside of sci access the full context sci has when that function is called from within eval-str
? (sorry still stuck on some weird code walking stuff)
don't want you to waste too much time thinking about this haha it's probably a bad idea and/or not possible
I have it somewhat working if I hardcode the same args passed to eval-string internally
I'm trying to figure out if what you want is already supported. So unless you give me your technical requirements and background, I can't help you very much
do you need something like this? https://github.com/borkdude/sci/#state
I’m trying to get macros in javelin (https://github.com/hoplon/javelin) working with sci on cljs. Namelly the cell=
macro, which does elaborate code walking. I want this so that I can use javelin inside a sci repl ui inside a browser
(def x (cell 1))
(def y (cell= (+ x 2)))
@y ;;=> 3
(macroexpand-1 '(javelin.core/cell= (+ x 2)))
((javelin.core/formula (fn [gen1] (+ gen1 2))) x) ;;simplified
cell=
basically walks the whole form you pass it and extracts all symbols which might be cells, and then extracts them, and puts the rest of the body in a function that is passed to javelin’s formula
function, which returns another function to apply to those symbols
Macroexpansion must be done on the form you pass cell=, and I belive that’s where the problem is. Then macroexpansion needs to include the outside env
, and javelin obviously expects the env
that clojurescript macros use (which is different than sci’s &env, or the regular clj macro &env
)
I basically need to get this working in sci
https://github.com/hoplon/javelin/blob/557b51ce14f31c391aefa8a22c8c2aa42db7b269/src/javelin/core.clj#L219
So I beleive the problem line of the file I’m trying to adapt to sci is:
https://github.com/hoplon/javelin/blob/557b51ce14f31c391aefa8a22c8c2aa42db7b269/src/javelin/core.clj#L65@jjttjj what might help is looking at https://github.com/borkdude/babashka/blob/7dc1fab97698ab80d53351a8b4d7f3149790feee/src/babashka/main.clj#L356 there I first create the ctx because I have some functions that need it, like the REPL
it is a private API so things might chance, so use it at your own risk. if it works for your kind of problem, we can try make it public
oh yeah, I didn't think to use the internal eval-string*
even though I was using other internal stuff (lke macroexpand-1), i think with both these I should be able to get it to work
ok make it work and if it works, please bother making an issue with the stuff you needed from the impl namespaces, so we can make it public and document it
I also created the sci-ctx once, so if you eval multiple expressions in the REPL you don't need to re-create it every time, which saves like 1 ms on every call because it avoids merging hash-maps (options + defaults) 😉
Ok cool will do, my brain is a bit fried from messing with this all day, but will keep you posted and have a better explanation of what's going on when it becomes unfried, thanks again!
I remember that hato was a something of a non-starter for inclusion in babashka, but what about including HttpClient and WebSocket classes themselves? Too low level to be useful? or are they what was causing the issues?
I'm inclined to go the curl route: https://github.com/borkdude/babashka.curl curl can also do websockets: https://gist.github.com/htp/fbce19069187ec1cc486b594104f01d0