Fork me on GitHub
jason poage00:07:13

i found this here but of course, i still cant get it to work.

Ian Fernandez01:07:21

hey guys, I'm new to spec instrumentation

Ian Fernandez01:07:58

I'm having this error:

:sym ..../position-gen,
  :failure #error {
 :cause nil
 [{:type java.lang.IndexOutOfBoundsException
   :message nil
   :at [clojure.lang.RT nthFrom "" 928]}]

Ian Fernandez01:07:10

for these:

(defn position-gen [len]
  (rand-nth (range (dec (or len 50)))))

(s/fdef position-gen
  :args (s/cat :len int?)
  :ret ::sc/length
  :fn  #(>= (% :args) (% :ret)))

Ian Fernandez01:07:22

mine s/fdef as "a too open definition"?

Alex Miller (Clojure team)01:07:25

your spec is not restrictive enough to accurately describe the valid inputs

Ian Fernandez01:07:11

(s/fdef position-gen
  :args (s/cat :len pos-int?)
  :ret nat-int?  
  :fn  #(>= (% :args) (% :ret)))
isn't restrictive too =<

Alex Miller (Clojure team)01:07:41

like what if len is -5 ?

Alex Miller (Clojure team)01:07:07

user=> (rand-nth (range -5))
Execution error (IndexOutOfBoundsException) at user/eval3 (REPL:1).

👍 4
clj 4
Ian Fernandez01:07:35

pos-int? / nat-int?

Ian Fernandez01:07:08

there's a way to pass a function that

has 0 arguments?

Alex Miller (Clojure team)01:07:30

usually :args (s/cat) is best

clj 4
Ian Fernandez01:07:22

i've not found that

Ian Fernandez01:07:11

(s/fdef position-gen
  :args (s/cat :len pos-int?)
  :ret nat-int?  
  :fn  #(>= (% :args) (% :ret)))
isn't restrictive too =<


So am having issue starting lein. lein repl or lein --version or any...


@simon What's in your .lein/profiles.clj file?


Comment out the :plugins and :dependencies lines and see if that fixes your problem.


Yeah, it does. Thanks. Btw, the issue started when I upgraded lein. Bumping up the deps all works...


Also, does this happen just in a particular project directory, or also when there is no project.clj file present?


i'm calling an api that returns a collection of results, but the response is paged, which means multiple calls to get the whole dataset. what's a good technique for processing the entire collection?


lazy sequences seems like a trick-gimmick that would work, but lazy-sequences with side effects isn't a good idea


i only want to fetch the pages i need, rather then fetch it all up front and then process it


How do you know which pages you need?


each record has a timestamp, and i process the records in descending order (by timestamp) until i encounter a record i've already seen (from a previous execution)


the api doesn't let me filter out only the records i need


So if you had an API call that returned a lazy sequence (I am not yet saying I know that is possible and/or easy to do), you could do a take-while on it?


This actually sounds like one of the specific use cases that core.async was designed for. Create a blocking channel that can hold twice as many records as you get in a single API call, and then, inside a go loop, get a page of data and put it on the channel. If the channel is full, wait for it to have enough room before going to get the next page.


Caveat: I haven’t worked that much with core.async so I may not know all the gotchas, but I’m looking at the docs and it seems like this should be the “right” way to go.


@manutter51 how does the producer know when to stop/exit cause the consumer is finished?


I would put the test for “I’ve seen this one already” inside the loop that makes the actual API calls. Once the “seen” record shows up again, just close the channel. I believe that there’s a way for the publish side of the channel to mark it as closed without losing the data that’s still in the buffer.


I don’t have code for how to do this (and I have to go afk for a bit), but that’s the direction I’d explore.


interesting tips, thanks, i'll investigate

Alex Miller (Clojure team)12:07:32

don't use lazy sequences when you need control over an external source

Alex Miller (Clojure team)12:07:55

you probably also don't need core.async (and if you do use it, don't use a go loop for the IO - put that in a thread)

Alex Miller (Clojure team)12:07:31

or use pipeline-blocking

Alex Miller (Clojure team)12:07:55

but really, I'd probably just use a loop/recur for exercising the api


That’s good for me to know too.

Noah Bogart14:07:25

quick java-related question: when i run lein uberjar for a specific project, it'll produce the same jar file on my machine as it will on another machine, provided we both have the same versions of java, clojure, and lein installed, right?


but there are other factors that may make it unreproducible @nbtheduke


like stray files in the git repo, stale files in the AOT directory (target/classes I believe for lein)

Alex Miller (Clojure team)14:07:08

lein plugins / profiles

Noah Bogart14:07:24

I have an app deployed on a digital ocean box, and it sometimes runs out of space when i run lein uberjar, so i was thinking of running it locally and then scp-ing it over, but I don't wanna break things in the mean time if that's not gonna work


@nbtheduke if you can create the uberjar in the same conditions that it's usually created (profiles, versions, clean checkout) then it's probably fine

Noah Bogart14:07:19

cool, that's encouraging. I'll try it out! thanks


Hey, I am having issues with lein swank. My ~/.lein/profiles.clj looks as follows {:user {:plugins [[lein-swank "1.4.5"] ]}}.


When I use 1.9.0 everything works as expected, but with 1.10 I get Call to clojure.core/ns did not conform to spec..


Let me know if you want me to paste the whole stacktrace somewhere.


that's a super old dependency that probably has issues


you can set a JVM property to prevent spec macro checking


which is where it is failing


but I haven't even heard the word swank in 5 years


can I prevent the spec macro checking just for that dependency


no, it's a jvm wide setting



Renan Oliveira15:07:25

Hi Guys, I have a doubt, what do you using to response in json in pedestal?


io.pedestal.http/json-body interceptor

Mario C.15:07:18

I am looking for something like cond-> but not sure if its provided by clojure. Basically I want to test a value/expression for true or false if its true then apply a transformation and pass it to the next test. If its false skip it. Until a final value/expression is reached. In others words, cond-> but with the ability to use the result in the true case of the previous clause in the next condition. Does that make sense?


collection operations don't need to check if things are empty


(filter whatever empty-list) -> returns an empty list


also, note the documentation for empty?:


user=> (doc empty?)
  Returns true if coll has no items - same as (not (seq coll)).
  Please use the idiom (seq x) rather than (not (empty? x))

Mario C.16:07:41

@U050ECB92 That was just examples I threw out there for the sake of making an example. But you're right

Mario C.16:07:05

@UHK8B8STX I guess I could use as-> and make a series if-elses but I was trying to avoid that

Mario C.16:07:22

Unless there is something I am not seeing

Mario C.16:07:16

@U04V70XH6 Yes, its exactly what I was looking for


Yeah, I use those a lot at work and I see people ask for them fairly regularly, that's why we open sourced that little library.

Mario C.16:07:29

yea it looks really useful

Mario C.15:07:08

(cond-> initial-value 
  (not (empty? initial-value)) (map + initial-value) 
  (empty? (filter even? <result-of-previous-mapping>)) true)

Mario C.15:07:38

I guess I would need a short circuit too

Ahmed Hassan15:07:06

How can I do something like this in aliases of CLI Deps? ["trampoline" "run" "-m" "app.server/run-dev"]

Ahmed Hassan15:07:43

I mean running a function other than -main.


Hi. I’m trying to get my head around browser vs. server routing, I’m messing things up in my app. I’m using bidi and pushy on the client, and am successfully processing the requested url:

(defn- dispatch-route
  (log/info "Matched route" matched-route)
  (let [route (:handler matched-route) ]
    (condp = route
      :edit-feature (rf/dispatch [:editing-feature 
                                  (get-in matched-route :route-params :id) ])
      :alexandria-home (do (log/info "In home dispatch") (rf/dispatch [:editing-feature "home"]))


In that code, clicking a link with href=“/editfeature/123” works to set the :editing-feature key in the app-db.


However my browser then navigates to /editfeature/123 which is a 404.


I don’t want it to navigate away from the displayed page, I intend to use that key in the app-db to bring up a modal edit dialog.


I assume it has something to do with my serverside routing, which uses Compojure


(compojure/defroutes app
  (-> (compojure/routes
        (compojure/GET "/" [] (slurp (io/resource "public/index.html")) 
        (route/resources "/")
        api/routes )

Ville Vuorinen16:07:50

clojure + lein + java11, WARNING: Illegal reflective access by clojure.lang.InjectedInvoker/0x0000000800232040 (file:/Users/idk/.m2/repository/org/clojure/clojure/1.10.1/clojure-1.10.1.jar) to method

Ville Vuorinen16:07:53

“Perhaps the best is to provide type hints to the exported types so the call is no longer reflective:”


@ville I suspect the actual reflective access is coming from elsewhere and the message is misleading. Clojure 1.10.1 is tested on JDK11 so it should be fine. What version of Leiningen are you using?

Ville Vuorinen17:07:02

Leiningen 2.9.1 on Java 11.0.3 Java HotSpot(TM) 64-Bit Server VM


it's unclear from the warning whether it's the lein jvm or the project jvm that's causing the issue. If it's the project, add --illegal-access=debug to :jvm-opts, if it's lein, add it to an environment variable LEIN_JVM_OPTS


if you add --illegal-access=debug you'll get a bit better trace about what is reflecting specifically


right now it points to the clojure.jar itself, because that's where clojure's reflection mechanism lives


but the root of the warning is user code that is triggering the reflection mechanism


If I'm creating a tools.deps based project and want certain folders excluded from the classpath (say my src/migrations dependencies excluded from a container that only hosts the web or service portion of my app) would it be better to just copy the subfolders when creating the environment, and include the deps in :extra-deps. I've been experimenting with having any non-app related clojure code on top-level folders for example migratus for my migration code that won't be loaded unless you explicitly call the alias that adds that folder. For people that actually deployed code that has a lot of this type of support code, or multi-enviroment setup, do you care if extra dependencies are even loaded, am I overthinking this?


If it isn't source code, don't put it in src, use resources or a folder under that.


If it is source code, and you still want some control, use src/clj for your Clojure code (and src/migrations for the migration code) and then use :paths ["src/clj"] by default and aliases to bring in :extra-paths ["src/migrations"] as needed.


I like that route


I'm looking for a resource (book chapter, article, tutorial, blog post, video, etc) on interacting with API's through ClojureScript.


@anantpaatra Are you interested in writing ClojureScript that interacts with JavaScript APIs? (In other words, are you interested in JavaScript interop from ClojureScript?)


Or, are you perhaps interested in how to call a JSON-based HTTP API?


Hah, the 2nd one? (JSON-based HTTP API)?


I'm interested in both actually hehe


Sorry for the ambiguous answer.


No problem 🙂


I’m trying to add [org.apache.wss4j/wss4j "2.2.3" :extension "pom"] to my lein project, but I am unable to use java classes from that library


I want (import '[org.apache.wss4j.dom.message WSSecHeader]) to work but intellij appears to not find the classes correctly