Can't wait to see what you come up with ; )
I always wanted to do something like that with a code-city type thing
have the clojure bits be little floating orbs
the java around it be the city buildings
im trying to use reader conditionals, but im getting a Syntax error reading source at (src/x.clj:4:7). Conditional read not allowed
error:
(ns x
(:require
[x]
#?(:clj [y])))
according to the official docs on the topic - https://clojure.org/guides/reader_conditionals - this should work.
this is the example from the docs:
(ns rethinkdb.query
(:require [clojure.walk :refer [postwalk postwalk-replace]]
#?(:clj [<http://rethinkdb.net|rethinkdb.net> :as net])))
it should be .cljc
, not .clj
the reason im trying is because i would like to have a script which works both in babashka and jvm clojure.
i tried it with clojure 1.10.1 and 1.10.3; both fails with the same error
rename it to x.cljc
I think you should use .cljc if you are also targeting clj(s). It should be easy to set up .bb for editors. For Cursive, Settings > Editor > File Types
Sorry @oneatom. It was late and I misread the question!
> i was just pondering about what would it take to support the .bb extension from cursive and emacs and would i want the .bb extension behave the same as the .cljc extension
@onetom in Emacs (add-to-list 'auto-mode-alist '("\\.bb$" . clojure-mode))
should suffice
libs (that are orthogonal to IDEs) like tools.reader, tools.namespace, etc won't recognise .bb
though
> To use reader conditionals, all you need is for your file to have a .cljc extension.
is there a way to influence clojure to handle .bb
extension the same way as the .cljc
extension?
Babashka is a different sort of environment to Clojure or ClojureScript. It does seek to be like Clojure, and even includes some JVM classes, but it is still different. Itâs not trying to be like a JavaScript environment, so conditional compilation is not really appropriate
you can add it and clojure will ignore it. up to babashka to look for bb files but that's by definition not clojure's concern
i think babashka has its own reader tag for its own pathways
i was just pondering about what would it take to support the .bb
extension from cursive and emacs and would i want the .bb
extension behave the same as the .cljc
extension, but i guess it doesn't really worth the complications, so i will just use .cljc
.
@quoll this is my use-case:
#?(:bb
(do
(require '[babashka.pods :as pods])
(pods/load-pod 'org.babashka/aws "0.0.5")))
(ns xxx.aws
(:require
#?(:bb [pod.babashka.aws :as aws.api]
:clj [cognitect.aws.client.api :as aws.api])))
this way i can have a convenience layer on top of the cognitect aws api lib, which i can use from both babashka and clojure.the benefit of using it from babashka is that i can spin up a repl extremely fast and have access to all the aws apis, without explicitly adding them as dependencies into my deps.edn
.
and the list of deps is long...
https://raw.githubusercontent.com/cognitect-labs/aws-api/master/latest-releases.edn
hi - is there any default setting with clj deps which might prevent accessing a Jetty port from another machine when I start my app up with âclj -m x.yâ ?
clojure cli is exclusively for constructing class-path. It knows nothing about exposed ports or any other resources.
Iâm trying to use the built-in WatchService in JDK 11 and set com.sun.nio.file.SensitivityWatchEventModifier/HIGH
(to make it not take 5-10 seconds). It seems to have recently been moved to a jdk.unsupported
module, but I canât get it to work:
$ clojure -J--add-modules -Jjdk.unsupported -e '
(.register (java.nio.file.Paths/get (java.net.URI. "file:/"))
(.newWatchService (java.nio.file.FileSystems/getDefault))
(into-array (type java.nio.file.StandardWatchEventKinds/ENTRY_CREATE) [java.nio.file.StandardWatchEventKinds/ENTRY_CREATE])
com.sun.nio.file.SensitivityWatchEventModifier/HIGH)'
WARNING: When invoking clojure.main, use -M
Execution error (ClassCastException) at user/eval1 (REPL:2).
class com.sun.nio.file.SensitivityWatchEventModifier cannot be cast to class [Ljava.nio.file.WatchEvent$Modifier; (com.sun.nio.file.SensitivityWatchEventModifier is in module jdk.unsupported of loader 'bootstrap'; [Ljava.nio.file.WatchEvent$Modifier; is in module java.base of loader 'bootstrap')
any pointers?@mkvlr register
expects an array of modifiers since its variadic in java WatchEvent.Modifier... modifiers
. so it fails because you are missing a into-array
call as above
don't need to bother with the modules otherwise. shadow-cljs also uses that watcher and runs fine in jdk8-15 so far
@thheller thank you, that was it, works with (into-array (type com.sun.nio.file.SensitivityWatchEventModifier/HIGH) [com.sun.nio.file.SensitivityWatchEventModifier/HIGH])
How can I test that something taps what I expect?
Somthing similar to with-out-str
would be nice, like with-tap-str
, haha.
to me, tapping shouldn't be an observable and required part of something. but surely you could just redef tap> and ensure that something is called, or have tap> passed into the function under test so that you can pass in #(reset! tapped %)
in your test suite
@pez You could add-tap
your own stateful listener test function.
Ah, that sounds like it should work for my use case.
(def tapped (atom nil))
(defn- save-tap [v] (reset! tapped v))
...
(add-tap save-tap)
.. run test: assert @tapped is what you expect ..
(remove-tap save-tap)
Indeed. It sounds a bit odd to want to do this. But Iâm writing a macro that should tap things, and want to test the macro some. đ
Works like a charm. Thanks!