Fork me on GitHub

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
    #?(:clj [y])))
according to the official docs on the topic - - this should work. this is the example from the docs:
(ns rethinkdb.query
  (:require [clojure.walk :refer [postwalk postwalk-replace]]
            #?(:clj [ :as net])))


i tried it with clojure 1.10.1 and 1.10.3; both fails with the same error


it should be .cljc , not .clj

👍 3

the reason im trying is because i would like to have a script which works both in babashka and jvm clojure.


rename it to x.cljc

❤️ 3

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.


@U051N6TTC this is my use-case:

     (require '[babashka.pods :as pods])
     (pods/load-pod 'org.babashka/aws "0.0.5")))

   #?(:bb  [ :as aws.api]
      :clj [ :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...


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

👍 3

Sorry @oneatom. It was late and I misread the question!

👍 3

> 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 @U086D6TBN 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

❤️ 3

> To use reader conditionals, all you need is for your file to have a .cljc extension.


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.

👍 6

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 ( "file:/"))
           (.newWatchService (java.nio.file.FileSystems/getDefault))
           (into-array (type java.nio.file.StandardWatchEventKinds/ENTRY_CREATE) [java.nio.file.StandardWatchEventKinds/ENTRY_CREATE])
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

🙏 3

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])

👍 3

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


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. 😃


@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)

❤️ 6

Works like a charm. Thanks!