Fork me on GitHub
#clojure
<
2021-03-16
>
onetom05:03:28

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 [ :as net])))

onetom05:03:45

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

vlaaad08:03:18

it should be .cljc , not .clj

👍 3
onetom05:03:15

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

dpsutton05:03:06

rename it to x.cljc

❤️ 3
onetom05:03:43

is there a way to influence clojure to handle .bb extension the same way as the .cljc extension?

quoll05:03:35

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

dpsutton05:03:39

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

dpsutton06:03:24

i think babashka has its own reader tag for its own pathways

onetom06:03:00

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.

onetom06:03:15

@U051N6TTC 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.

onetom06:03:34

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

nilern07:03:45

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
quoll12:03:01

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

👍 3
vemv15:03:33

> 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
dpsutton05:03:26

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

rossputin09:03:33

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’ ?

delaguardo09:03:45

clojure cli is exclusively for constructing class-path. It knows nothing about exposed ports or any other resources.

👍 6
mkvlr09:03:43

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?

thheller09:03:15

@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
thheller09:03:50

don't need to bother with the modules otherwise. shadow-cljs also uses that watcher and runs fine in jdk8-15 so far

mkvlr09:03:53

@thheller thank you, that was it, works with (into-array (type com.sun.nio.file.SensitivityWatchEventModifier/HIGH) [com.sun.nio.file.SensitivityWatchEventModifier/HIGH])

👍 3
pez21:03:41

How can I test that something taps what I expect?

pez22:03:47

Somthing similar to with-out-str would be nice, like with-tap-str, haha.

dpsutton22:03:02

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

pez22:03:44

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

seancorfield22:03:04

@pez You could add-tap your own stateful listener test function.

pez22:03:53

Ah, that sounds like it should work for my use case.

seancorfield22:03:21

(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
pez23:03:08

Works like a charm. Thanks!