clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
2021-03-16T00:17:55.149800Z

Can't wait to see what you come up with ; )

emccue 2021-03-16T00:46:45.150Z

I always wanted to do something like that with a code-city type thing

emccue 2021-03-16T00:46:53.150200Z

have the clojure bits be little floating orbs

emccue 2021-03-16T00:47:02.150400Z

the java around it be the city buildings

onetom 2021-03-16T05:09:28.001500Z

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

vlaaad 2021-03-16T08:04:18.009700Z

it should be .cljc , not .clj

1👍
onetom 2021-03-16T05:10:15.002200Z

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

onetom 2021-03-16T05:11:45.002300Z

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

dpsutton 2021-03-16T05:14:06.002600Z

rename it to x.cljc

1❤️
nilern 2021-03-16T07:06:45.009500Z

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

1👍
quoll 2021-03-16T12:43:01.017800Z

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

1👍
vemv 2021-03-16T15:06:33.018600Z

> 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

1❤️
dpsutton 2021-03-16T05:14:26.002800Z

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

onetom 2021-03-16T05:19:43.003Z

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

quoll 2021-03-16T05:40:35.008Z

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

dpsutton 2021-03-16T05:54:39.008200Z

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

dpsutton 2021-03-16T06:05:24.008400Z

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

dpsutton 2021-03-16T06:05:52.008600Z

https://book.babashka.org/#_reader_conditionals

onetom 2021-03-16T06:22:00.008900Z

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.

onetom 2021-03-16T06:24:15.009100Z

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

onetom 2021-03-16T06:25:34.009300Z

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

nilern 2021-03-16T07:06:45.009500Z

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

1👍
vlaaad 2021-03-16T08:04:18.009700Z

it should be .cljc , not .clj

1👍
rossputin 2021-03-16T09:12:33.010800Z

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

2021-03-16T09:21:45.011800Z

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

2👍
mkvlr 2021-03-16T09:40:43.013800Z

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?

thheller 2021-03-16T09:49:15.014900Z

@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

1🙏
thheller 2021-03-16T09:51:50.015800Z

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

mkvlr 2021-03-16T09:55:53.016500Z

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

1👍
quoll 2021-03-16T12:43:01.017800Z

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

1👍
paul931224 2021-03-16T15:03:59.018400Z

well me too, but a city would be hard for first, hope can do something in reagent with svg-s with the gathered data from the analysis.

vemv 2021-03-16T15:06:33.018600Z

> 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

1❤️
pez 2021-03-16T21:33:41.020400Z

How can I test that something taps what I expect?

pez 2021-03-16T22:13:47.021300Z

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

dpsutton 2021-03-16T22:19:02.022700Z

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

seancorfield 2021-03-16T22:38:04.023300Z

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

pez 2021-03-16T22:38:53.024900Z

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

seancorfield 2021-03-16T22:39:21.025500Z

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

2❤️
pez 2021-03-16T22:41:44.025700Z

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 2021-03-16T23:12:08.026100Z

Works like a charm. Thanks!