Comments (8)
maybe an alternative more specific but trivial fix could be to explicitly add a cast (long ms) inbabashka.impl.clojure.core.async/timeout
For sure, we can do this.
The other issue may not be as easily fixable. The Clojure compiler will emit a byte code operation to cast a java.lang.* boxed object to a primitive and will then invoke the method on the primitive, but since babashka is basically using clojure.lang.Reflector it works similarly when using reflection in Clojure.
from babashka.
Yes, that is definitely it.
from babashka.
methods are resolved through reflection. See sci.impl.reflector
which is largely based on clojure/lang/Reflector.java
. A similar thing happens in clj when using reflection:
$ clj
Clojure 1.10.3
user=> (type (int 1))
java.lang.Integer
user=> (def x (int 1))
#'user/x
user=> (type x)
java.lang.Integer
user=> (Thread/sleep x)
Execution error (IllegalArgumentException) at user/eval5 (REPL:1).
No matching method sleep found taking 1 args
from babashka.
Btw, note that (long x)
does work.
from babashka.
Interesting. Your example with the indirection through the x
variable works for me when using JVM 17 but indeed throws when using JVM 20 (tested using Clojure 1.10.3 and Clojure 1.11.1). Not sure what's going on here.
As far as I can tell the method is correctly resolved in any case if a type hint is used:
(def x (int 1))
(Thread/sleep ^int x) ;; works on JVM 17 and 20
In Java, both long
and int
arguments are supported as well:
int x = 1000;
Thread.sleep(x); // works on JVM 17 and 20
I also just checked that the example from my first post ((Thread/sleep (int 1000))
) worked in Babashka v1.1.173 but no longer works since v1.2.174.
Of course, I agree that this issue is easy to circumvent in ones own code. The reason I initially noticed this bug was due to this line of code in the throttler library (which in turn calls Thread/sleep
here), which I use in one of my BB scripts and which stopped working after an update of BB.
While the specific issue I encountered is easy to fix/circumvent (e.g., by forking throttler or, as a quick-and-dirty solution, by altering the var roots of the affected functions at runtime in userland), the change of behaviour introduced in v1.2.174 could maybe cause other unforeseen incompatibilities with other Clojure libraries that worked previously with Babashka.
If this issue turns out to be not easily fixable, maybe an alternative more specific but trivial fix could be to explicitly add a cast (long ms)
inbabashka.impl.clojure.core.async/timeout
implementation.
from babashka.
Ah ok, I see, that makes sense.
Just out of curiosity, do you have an idea, what might have caused the difference in behaviour from BB v1.1.173 to v.1.2.174? Maybe the upgrade from Java 11 to 19?
from babashka.
Thanks! 😄
from babashka.
A better fix underway as part of issue #1513. Will be fixed in next release, everything will just work for Thread/sleep
from babashka.
Related Issues (20)
- Caching issue with relative local/root by same name, used in bb.edn in different directories HOT 1
- Resolve bb.edn when script is invoked via symlink HOT 1
- No dispatch macro for: ? HOT 9
- metadata added by read-string (as compared to clj implementation). HOT 9
- Embedding META-INF/bb.edn with :deps results in: Cannot run program "java"
- bb execution fails on Gentoo HOT 6
- Adding javax.net.ssl.SSLSocket and javax.net.ssl.SSLSocketFactory? HOT 33
- Static-linked binary file for armv7(32-bit) platform. HOT 1
- hash-ordered-coll not found in clojure.core HOT 1
- Try to support latest changes in at-at
- Wrapping built-in timbre/log! throws an error HOT 3
- exec-task description
- bb --version could run without a JVM HOT 3
- Can't use a lambda in a babashka's task HOT 2
- Babashka's `use-fixtures` doesn't add `:clojure.test/*-fixtures` metadata to namespace
- Dynamic var *test-out* not properly bound when clojure.test is called from within the nrepl
- bb should error when bb.edn does not contain exactly one valid form HOT 4
- Feature request: Expose flatland.ordered.set/ordered-set HOT 1
- command line separation with -- broken in several context HOT 10
- Make transcriptor work
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from babashka.