Fork me on GitHub
#babashka
<
2020-02-04
>
borkdude10:02:00

babashka v0.0.69: small bugfix release, fix for BABASHKA_PRELOADS

stijn11:02:48

is there a way to verify if something is a core async channel?

(satisfies? clojure.core.async.impl.protocols/ReadPort ...)
==> clojure.lang.ExceptionInfo: Could not resolve symbol: satisfies? [at /home/stijn/Documents/code/vouch/ops-tools/src/vouch/ops/run/main.clj, line 19, column 8]

stijn11:02:27

(instance? clojure.core.async.impl.channels.ManyToManyChannel ...)
==> clojure.lang.ExceptionInfo: Unable to resolve classname: clojure.core.async.impl.channels.ManyToManyChannel

borkdude11:02:49

how does one do this normally with core.async? I should probably add satisfies? to sci

borkdude11:02:55

PR welcome btw

stijn11:02:01

what works is

(try (println (async/<!! result))
  (catch IllegalArgumentException e
    (println result)))

stijn11:02:42

there is some discussion about how this should be done, currently the only way is to rely on the clojure.core.async.impl namespaces https://clojure.atlassian.net/browse/ASYNC-74

borkdude11:02:57

yeah, I guess I could add the impl namespace with the predicate

borkdude11:02:02

or you could do it using a PR 🙂

stijn11:02:13

I will give it a try

stijn11:02:46

there is no predicate currently, only satisfies? or instance? will work

stijn11:02:41

I'll take a look at sci this evening, might ask you some questions if I can't figure it out 🙂

borkdude11:02:43

ok, I added satisfies? to bb master now. but I think we need something more than this

borkdude11:02:06

you can take a look at the commit how this is done, for next time if something is missing

stijn11:02:44

ok, thanks, i will try it later today.

borkdude11:02:12

but to make this work we also need to resolve clojure.core.async.impl.protocols/ReadPort in bb and I'm not sure what this "thing" is, a var, a class?

stijn11:02:10

(defprotocol ReadPort
  (take! [port fn1-handler] "derefable val if taken, nil if take was enqueued"))

borkdude11:02:00

yeah, but when I evaluate that symbol, I get:

clojure.core.async.impl.protocols/ReadPort
{:on clojure.core.async.impl.protocols.ReadPort, :on-interface clojure.core.async.impl.protocols.ReadPort, :sigs {:take! {:name take!, :arglists ([port fn1-handler]), :doc "derefable val if taken, nil if take was enqueued"}}, :var #'clojure.core.async.impl.protocols/ReadPort, :method-map {:take! :take!}, :method-builders {#'clojure.core.async.impl.protocols/take! #function[clojure.core.async.impl.protocols/eval10217/fn--10218]}}
, so what is that?

borkdude11:02:24

@stijn This now works on master:

$ ./bb '(satisfies? clojure.core.async.impl.protocols/ReadPort (async/chan))'
true

borkdude11:02:42

(was easier than I thought, although I don't know exactly how satisfies? works)

borkdude11:02:15

if you need to add more protocols, then I trust you can figure it out using the previous two commits. there are links to newly built binaries in #babashka_circleci_builds

stijn12:02:45

ok, thanks a lot! yes, commits make sense to me

borkdude12:02:51

@stijn should work with these from #babashka_circleci_builds : [linux - master@d3f1b051022e1979c9c25944c4374aa8f38622f0]: https://3997-201467090-gh.circle-artifacts.com/0/release/babashka-0.0.70-SNAPSHOT-linux-amd64.zip [12:46 PM] [macos - master@d3f1b051022e1979c9c25944c4374aa8f38622f0]: https://3996-201467090-gh.circle-artifacts.com/0/release/babashka-0.0.70-SNAPSHOT-macos-amd64.zip

stijn14:02:10

yes, verified this works!

stijn14:02:49

also, I did not know that babashka supported reader conditionals, that's really nice

stijn14:02:11

are you ok with a PR with some additional class imports from Java > https://github.com/borkdude/babashka/blob/master/src/babashka/impl/classes.clj?

stijn14:02:09

oh, hold on, it has the newer java.time, then maybe a PR is not even needed 🙂

borkdude14:02:07

which classes were you going to suggest?

jeroenvandijk16:02:13

I'm reaching next level complexity with Sci and cljsjs interop 🙈

borkdude16:02:44

cljs-js even?

jeroenvandijk16:02:57

maybe i just thought it was easy and I need to be patient

jeroenvandijk16:02:53

Ah yeah, I'm trying this package now for http requests https://github.com/cljsjs/packages/tree/master/axios

borkdude17:02:48

@jeroenvandijkSo you are evaluating the CLJS code from that package in sci?

borkdude17:02:54

That's interesting

jeroenvandijk17:02:14

I'm not completely sure what I'm doing anymore. I'll break it down in smaller steps

jeroenvandijk17:02:21

My first approach didn't work unfortunately

jeroenvandijk17:02:05

I wanted to use two seperately compiled scripts (Sci and my Aws code) together

jeroenvandijk17:02:30

This works in normal mode, but in advanced compilation it fails (maybe obviously)

borkdude17:02:49

"my AWS code" is written in normal CLJS?

jeroenvandijk17:02:18

So now I'm trying to combine things from one script. I forgot why the npm request module didn't work. I need to take better notes 🙈

jeroenvandijk17:02:05

> > "my AWS code" is written in normal CLJS? > > Yeah I ported the signing part of https://github.com/cognitect-labs/aws-api/ to CLJS > >

borkdude17:02:48

if you compile that to advanced, then your functions will be renamed, so that might be the issue? if you add ^:export metadata, those functions will not be renamed.

jeroenvandijk17:02:28

I'll prepare some examples of what doesn't work. It became a bit of a mess (in my head)

jeroenvandijk17:02:15

I've tried ^:export in a few ways. Probably I've still missed a working combination

jeroenvandijk18:02:38

The trick was indeed the ^:export, but I also have to require the libraries. E.g. global.request = require('request') https://gist.github.com/jeroenvandijk/c65dda62c086936704de657b2004eb8d#file-node_test-js-L13

jeroenvandijk18:02:58

cljsjs doesn't seem to help much. I don't understand why not

jeroenvandijk18:02:21

I'm also wondering why you didn't have to ^;export all the clojure functions for Sci. So still some unsolved riddles

jeroenvandijk19:02:14

Maybe it's because sci/eval-string touches all those functions in the compilation and my new function is not part of this

stijn19:02:07

@borkdude I was trying to use java.text.SimpleDateFormat and java.util.TimeZone, but it all works with java.time.

borkdude21:02:41

stijn: awesome

borkdude21:02:34

@jeroenvandijk: I actually have a slide about this in my upcoming presentation about babashka/sci:

jeroenvandijk21:02:28

I think I'm doing something similar. Apparantly not exactly the same 🙂

borkdude21:02:12

the map is not just used for holding to references, but also to look up functions

borkdude21:02:26

so even if CLJS advanced is going to rename things, this will still work, because we implement our own "resolve"

jeroenvandijk21:02:42

Smart 🙂

borkdude21:02:11

@stijn about your PR, just out of curiosity, why do you need the Long class?

borkdude21:02:40

I now also added it to :imports so it's available as just Long in addition to java.lang.Long

stijn21:02:29

@borkdude I'm trying to parse a long from command line args

borkdude21:02:42

and integer was not big enough? 😄

stijn21:02:03

yeah, it's for millis from epoch 🙂

borkdude21:02:07

ah, gotcha, thanks