Fork me on GitHub
#babashka
<
2022-04-04
>
tgg12:04:08

Not really sure where this belongs in the bb/nbb/sci world, but if you were wondering if you could use scittle in tampermonkey scripts...

// ==UserScript==
// @name         Do something
// @namespace    
// @version      0.1
// @description  try to take over the world!
// @author       You
// @require      
// @grant        none
// @run-at       document-body
// ==/UserScript==

(function() {
    'use strict';
    const script = '(js/console.log "hello world")';
    var scriptTag = document.createElement('script');
    scriptTag.type = 'application/x-scittle';
    scriptTag.appendChild(document.createTextNode(script));
    document.body.append(scriptTag);
})();

tgg12:04:29

I'm only now thinking in terms of "where is the strangest place I can use sci".

borkdude12:04:01

> where is the strangest place I can use sci This is good thinking! :) We do have a #scittle and #sci as well for this

tgg12:04:24

Ah, I thought I checked for #scittle... whoops!

borkdude14:04:59

#babashka 0.8.0 released. Major new feature is the ability to declare pods in bb.edn. This effort was largely driven by @cap10morgan 👏 See here for an example: https://book.babashka.org/#_pods_in_bb_edn Full changelogs with many other improvements: https://github.com/babashka/babashka/blob/master/CHANGELOG.md#080-2022-04-04 Next Saturday, @rahul080327 will present about #babashka at NovaLug: https://www.meetup.com/novalug/events/fzklrsydcgbmb/ - feel welcome to join!

🙌 6
🎉 1
cldwalker14:04:39

Thanks @cap10morgan for driving pods in bb.edn! Excited to try this out

👍 1
mal22:04:49

How’s this pod/bb.edn work in an https://github.com/redstarssystems/apptemplate project? I keep getting the error below. I tried it the “old” way too with the same results. I see the pod in my ~/babashka/pods/repository/org.babashka/go-sqlite3/0.1.0 manifest.edn, metadata.cache and pod-babashka-go-sqlite3. does it really need _‘s?

14:15 $ bb run
[ ] run 2022-04-04 14:29:09
Execution error (FileNotFoundException) at edu.mywork.www.myproject/eval138$loading (myproject.clj:1).
Could not locate pod/babashka/go_sqlite3__init.class, pod/babashka/go_sqlite3.clj or pod/babashka/go_sqlite3.cljc on classpath. Please check that namespaces with dashes use underscores in the Clojure file name. 

borkdude22:04:24

@UH1MELU4U Pods in bb.edn don't affect Clojure JVM code

borkdude22:04:23

I'm not sure what bb run is doing in your case

borkdude22:04:33

So the short answer is: pod config in bb.edn is for babashka code, not for Clojure JVM code. Perhaps @cap10morgan can help you further, it's late here.

mal22:04:20

Thx… think run is…

(defn run
  "Run application (-main function)"
  [& args]
  (when (:compile-java-sources? (config/get-project-env)) (javac-compile))
  (babashka.tasks/clojure (str "-M:run " (apply str (interpose " " args)))))

cap10morgan22:04:42

@UH1MELU4U Can I see the code that's misbehaving somewhere (preferably the whole project)?

mal22:04:07

@cap10morgan sure, it’s basically the stock app you get when creating an app as described in the readme. https://github.com/xicubed/recevent

mal23:04:50

@U097654L8 have you tried these pods in your apptemplate?

mike_ananev05:04:00

bb run is run main function of JVM app. So, I guess, running pods here is not good idea. Use pods for babashka tasks, not for JVM code

borkdude07:04:55

Pods do work in the JVM but have to include the pods library and use load-pods in the old way.

cap10morgan15:04:17

@UH1MELU4U Sorry, the steps I need to reproduce aren't jumping out at me from that README. Can you connect the dots a little bit more?

cap10morgan15:04:49

or maybe send a docker image that repros?

borkdude15:04:03

@cap10morgan It's been said a few times already, but mal is running in the JVM. The JVM does not support running pods declared in bb.edn

cap10morgan15:04:36

oh ok. saw the messages but didn't realize that was the full explanation. thanks!

mal22:04:55

Thanks for the tips - I'll poke at it later - down today after getting vaxxed.

tatut15:04:57

which JDK classes are available? is there a list, just noticed j.u.c.ExecutorService wasn't

tatut15:04:44

I can use ThreadPoolExecutor as that is on the list

borkdude15:04:30

Cool. Your older core.async code should now probably also work again in bb btw, due to a fix in 0.8.0

tatut15:04:26

nice... but I'm seeing this through anyway, good to take it out to shed the dependency

tatut15:04:46

the way I'm using it is lots of tiny go blocks that do nothing but write 1 value

tatut15:04:59

I can just use clojure core promises instead

tatut15:04:53

it seems every time I use core.async, I will live to (somewhat) regret it

tatut15:04:19

even when I have complicated process stuff that is a good fit for it, the CSP stuff ends up being way too complicated

borkdude15:04:09

Also in CLJS, the CSP stuff doesn't always work that well

borkdude15:04:25

I've heard ;)

tatut15:04:52

guess I'm not the only one

tatut15:04:25

but I think ExecutorService interface would be good to have, as I can't use it as a typehint to avoid reflection without it

borkdude15:04:55

ah it's only an interface? that would be a no-brainer to add I think

tatut15:04:39

ok, I'll circle back to it

borkdude15:04:09

you can install an intermediate version with:

bash <(curl ) --version 0.8.1-SNAPSHOT
once CI has finished building

tatut15:04:25

I'll try it

tatut15:04:48

but I got all the code loading now, sadly there is some difference with JVM and bb... the bb version is throwing

java.util.concurrent.CompletionException: java.io.IOException: Output closed
when trying to send to the websocket, where JVM version works... no other exceptions, will need to investigate still

tatut15:04:04

I'm hopefully close

borkdude15:04:33

Cool. Hopefully you'll be able to repro it

tatut16:04:08

seems the #object[.http.websocket.WebSocketImpl 0x...] object just starts out with both input and output closed... no idea why

borkdude16:04:14

Maybe @U0EHU1800 has an idea... ? I randomly think of him since we worked on getting the jdk.net.http stuff in bb

borkdude16:04:53

I can take a look later this week

tatut16:04:15

ah, found the problem

tatut16:04:01

but don't understand why

#error {
 :cause Not implemented: onOpen
 :via
 [{:type java.lang.Exception
   :message Not implemented: onOpen
   :at [babashka.impl.reify$reify_fn$reify__31871 onOpen reify.clj 64]}]
 :trace
 [[babashka.impl.reify$reify_fn$reify__31871 onOpen reify.clj 64]
  [java.lang.reflect.Method invoke Method.java 566]
  [sci.impl.Reflector invokeMatchingMethod Reflector.java 172]
  [sci.impl.interop$invoke_instance_method invokeStatic interop.cljc 39]
  [sci.impl.evaluator$eval_instance_method_invocation invokeStatic evaluator.cljc 188]
  [sci.impl.analyzer$analyze_dot$reify__9342 eval analyzer.cljc 820]
  [sci.impl.analyzer$return_if$reify__9276 eval analyzer.cljc 653]
  [sci.impl.fns$fun$arity_2__7886 invoke fns.cljc 107]
  [babashka.impl.reify$reify_fn$reify__31871 onOpen reify.clj 64]
...

tatut16:04:22

if you don't pass in :on-open handler, you will get that, but on jvm it works

tatut16:04:40

I don't get why this is the fallback that (reify WebSocket$Listener) I'd expect that to throw always as it implements nothing

tatut16:04:55

on JVM it does nothing

tatut16:04:54

reify docs say

Methods should be supplied for all methods of the desired
protocol(s) and interface(s).
so I guess we are in undefined behaviour territory

tatut16:04:26

and it works! nice

borkdude17:04:53

@U11SJ6Q0K Nice! I'll look into that incompatibility if you're willing to create an issue

borkdude17:04:04

I might have an idea

tatut04:04:49

but it doesn't seem to be the case in all interfaces

tatut04:04:29

I just tried with java.lang.Comparable and JVM clojure also throws exception when trying to invoke an undefined method

tatut04:04:35

ah, it must be related to default implementation

tatut04:04:27

I'm trying to find a good repro case and ran into

user=> (import '(java.util Comparator))
java.util.Comparator
user=> (def c (reify Comparator))
No matching clause: java.util.Comparator
^ that works in jvm clojure

borkdude20:04:17

Another version of neil published. Adds neil dep search command: https://twitter.com/borkdude/status/1511084119698165768

💪 1
🚀 3
Jan K23:04:41

I have encountered some strangely unhelpful error messages / stacktraces from babashka in some cases. This is my minimal script to reproduce:

#!/usr/bin/env bb
(ns my)

(defn myfn []
  (assert false))

(binding []
  (myfn)
  (try 1 (catch Throwable e)))
When I run this with babashka v0.8.0 I get this output with no context or location info:
----- Error --------------------------------------------------------------------
Type:     java.lang.AssertionError
Message:  Assert failed: false
When either the empty binding is removed (unwrapped), or the try-catch is removed, the resulting error message is much better:
----- Error --------------------------------------------------------------------
Type:     java.lang.AssertionError
Message:  Assert failed: false
Location: /home/jan/clj/automove/./errtest.bb:8:3

----- Context ------------------------------------------------------------------
4: (defn myfn []
5:   (assert false))
6: 
7: (binding []
8:   (myfn)
     ^--- Assert failed: false
9:   )

----- Stack trace --------------------------------------------------------------
my/myfn - /home/jan/clj/automove/./errtest.bb:4:1
my      - /home/jan/clj/automove/./errtest.bb:8:3
Is this some known limitation or a bug?

borkdude07:04:42

Probably something that can be improved. Issue welcome.