Fork me on GitHub

Re partial vs lambas ☝️: I've remember being told here (repeatedly) that lambdas are considered more idiomatic than partial and comp, and that it was backed up by pretty good reasons. There were possibly even references given, but nothing I can find now. 1) Can someone maybe help with a reference to the reasons to prefer lambdas?


They are often shorter, and often produce nicer stacktraces


The behavior of comp and partial when used to create top level defs can be surprising when you redefine things


I believe rich has at least once said partial wouldn't be part of clojure.core if the function short hand syntax had existed first


I think nicer stacktraces is the "big reason" I was looking for. Thanks!


They are also easier to debug - if that’s your thing; I find cider’s debugger very useful


I tend to prefer partial, as it clearly just binds parameters. Any #() needs to be read and understood. I am aware of the fact that there are downsides to partial wrt REPL driven development.


2) Why does the style guide suggest the opposite?


Is there a primitive operation that allows rotation of a vector?

; Left rotate once
[1 2 3] => [2 3 1]


(->> (range (count v)) (map #(rem (inc %) (count v))) (mapv #(get v %)))


this isn’t pretty, but its one way


I need to start using the threading macro...


Here's what I have so far (not working)

(defn mode [scale i]
  (let [b (subvec scale 0 i)
        r (map #(+ 12 %) (subvec scale i))]
    (map #(- (scale i) %) (conj r b))))


Most of that is normalizing values during the rotation which isn't relevant to this question


can you write out the unit tests for what you expect?


Honestly I don't know how atm xD I should definitely look into testing and spec ASAP. Thanks for the reminder.


I did luckily get it working, though. It ended up being pretty weirdly that order of the % in my lambdas...


I had to move the % to be the first param to the +/- ops.


(conj vector single-element-vector) does not work how I would have expected, though. End up with something like [1 2 3 (4)]


Ah, looks like I actually just fundamentally misunderstood what map is actually doing...


spec is something else - just learn clojure.test to start

Bob B04:10:10

could you conj the first element onto a subvec?

👍 1

i may be misunderstanding what you are trying to achieve but, (into [] (take 3 (drop 1 (cycle [1 2 3])))) just wrap it in a function that takes input an number of rotations. to generalize for left and right rotations use the length of the input in the drop


@U9VP9VCE6 FYI that worked very well for me. Thank you ❤️


👍 i am glad :) cycle is one of my fav clojure.core functions.


You can make one easily with peek pop and conj but nothing primitive


No I confused myself. Was working with a queue last sorry


is there a named function like ignore that does this (fn [& _] ) ?


(constantly nil)

👍 1

Is there anyway where we can debug how results are coming in a step for lazy-cat ? what value get into fib-seq-cat

(def fib-seq-cat
  (lazy-cat [0 1] (map + (rest fib-seq-cat) fib-seq-cat)))

(println (take 30 fib-seq-cat))


i am not getting how this behaving internally


I am trying to use clj and cljs in a monorepo and try to follow oakes' repo However, I have difficulty figuring out how to have a running repl. In the readme of that repo, it says use clj -M:cljs:dev to have a webpage running at http://localhost:3000 . With that command, it worked quite well but had no repl. I tried to modify it to clj -M:cljs:dev:repl/nrepl with the hope to have a repl running with nrepl server (I have in my ~/.clojure) but it didn't work out. Is there anyone have any suggestions or encounter similar problems?


btw, the deps.edn in ~/.clojure has the following alias snippest:

  {:extra-deps {nrepl/nrepl                {:mvn/version "0.8.3"}}
   :main-opts  ["-m" "nrepl.cmdline"]}

Jim Strieter14:10:09

Hi I'm following an exercise in Web Development With Clojure by Sotnikov, 3rd edition. Page 75 (Approx Location 1470 in Kindle) When I execute: $ curl localhost:3000 I am expecting to get an output like this: <html><body>Your IP is: 0;0;0;0;0;0;0;1</body></html> Instead, I get this: <html><body>Your IP Is:</body></html> Here is my core.clj: (ns ring-app.core (:require [ring.adapter.jetty :as jetty] [ring.util.response :as response] [ring.middleware.reload :refer [wrap-reload]])) (defn handler [request-map] (response/response (str "<html><body>Your IP Is: " (:remote-addr request-map) "</body></html>"))) (defn wrap-nocache [handler] (fn [request] (-> request handler (assoc-in [:headers "Pragma"] "no-cache")))) (defn -main [] (jetty/run-jetty handler {:port 3000 :join? false})) Why am I getting an IPv4 address instead of IPv6?


Depending on the OS, ipv6 will take precidence over ipv4, for example, on my Arch linux system:


❯ ping localhost
PING localhost(localhost (::1)) 56 data bytes
64 bytes from localhost (::1): icmp_seq=1 ttl=64 time=0.017 ms
64 bytes from localhost (::1): icmp_seq=2 ttl=64 time=0.069

Jim Strieter15:10:04

Yes but I am getting 4. I want 6


Interestingly enough, on my OS, running your code, I get this;


❯ http :3000                                                                                   
HTTP/1.1 200 OK
Date: Sat, 23 Oct 2021 15:30:12 GMT
Server: Jetty(9.4.42.v20210604)
Transfer-Encoding: chunked

<html><body>Your IP Is: [0:0:0:0:0:0:0:1]</body></html>




❯ curl -4 localhost:3000                                      
<html><body>Your IP Is:</body></html>%                                                                                                                                               
  ~                                                                                                                                                                                  system
❯ curl -6 localhost:3000
<html><body>Your IP Is: [0:0:0:0:0:0:0:1]</body></html>%


This would suggest that whatever you're using to query the endpoint on your machine, may be preferring to initiate the connection over ipv4, not ipv6, thus the server (jetty) is responding correctly.


curl -6 localhost:3000


check ip -6 ro

Jim Strieter15:10:10

::1 dev lo proto kernel metric 256 pref medium fe80::/64 dev enp0s3 proto kernel metric 100 pref medium


so you do have ipv6 in the system. what's the url you use in browser?


what's ping localhost

Jim Strieter15:10:32

PING localhost ( 56(84) bytes of data. 64 bytes from localhost ( icmp_seq=1 ttl=64 time=0.016 ms 64 bytes from localhost ( icmp_seq=2 ttl=64 time=0.019 ms 64 bytes from localhost ( icmp_seq=3 ttl=64 time=0.034 ms 64 bytes from localhost ( icmp_seq=4 ttl=64 time=0.017 ms 64 bytes from localhost ( icmp_seq=5 ttl=64 time=0.014 ms 64 bytes from localhost ( icmp_seq=6 ttl=64 time=0.041 ms 64 bytes from localhost ( icmp_seq=7 ttl=64 time=0.022 ms 64 bytes from localhost ( icmp_seq=8 ttl=64 time=0.025 ms 64 bytes from localhost ( icmp_seq=9 ttl=64 time=0.041 ms

Jim Strieter15:10:03

@UP82LQR9N oh good point lemme check...

Jim Strieter15:10:12

@UP82LQR9N the URL I use in the browser is: http://localhost:3000 Is that somehow limited to ipv4?


you need to check /etc/hosts


grep localhost /etc/hosts


mine is

$ grep localhost /etc/hosts      localhost
::1	       localhost

Jim Strieter17:10:58

Mine is identical

Jim Strieter17:10:04

Found the solution. Used: http://[::1]:3000 for the URL instead of the more common http://localhost:3000, which defaults to IPv4. But also had to turn off the browser's autofill option that was converting http to https, and then complaining that the connection is insecure.

Jim Strieter17:10:09

Thanks everyone!


i dont believe the app is ready for https. if browser hits https it will get an error. also your browser or system probably prefers v4 over v6.


Is there a name for that versioning scheme that Clojurians prefer - the one that is not semver?


Not really, although I do know a lot of projects (including my own), do prefer major.minor.commits over major.minor.patch


we could invent a new name for things like sometimes I use lots of dots in my version numbers 😄

Alex Miller (Clojure team)18:10:08

Clojure depends heavily on Maven, which does not understand that


Are there any commonly used release automation tools that work by looking at repo commits to create the changelog entries and follow the Maven way?

Jim Strieter15:10:16

I have no idea what that means


its a new question being asked, unrelated to the one you asked. you can maybe start a slack thread for your question?

Jim Strieter15:10:13

I'm trying to say that I have no idea what ::1 dev lo proto kernel metric 256 pref medium fe80::/64 dev enp0s3 proto kernel metric 100 pref medium means


ah right, i misunderstood


Hi all, I'm trying to use eastwood using the practicalli edn ( and get the error: Unknown error: java.lang.Exception: No file found for namespace example.core-test Anyone know what this is about or a way I can get it to skip the test directory so I can at least get it to run over my src? (Edit: Figured this out. The test path was set in the edn. I thought it was default) Thanks. Edit: I will add that the tests run with koacha and the code runs through repl and main and the idiom lint works, just not eastwood.


Sounds like its not picking up the namespaces under the test directory. A quick fix may be to also use the :env/test alias in the command

clojure -M:env/test:lint/eastwood
I'll also try adding test as an :extra-path in the eastwood alias


I do include the test path in the :main-opts part of that alias by default, so I may split the aliases into two, one with just src and and one with srce and test paths


Incidentally, I tend to use kaocha for testing and clj-kondo for linting, so probably havent tested eastwood in a while. If you have a project that has an issue with eastwood you can share, let me know.


@U05254DQM Just to let you know, adding env/test fixed my issue and I can now run eastwood including my tests. Thanks for the help!


Thanks for the feedback. I'll update the Eastwood alias with test as an extra-path.


Hey, is the possible to achieve the same behavior as

(jetty/run-jetty #'app {:port 3000, :join? false})
with a function like this:
(jetty/run-jetty (app inject-db-for-middleware) {:port 3000, :join? false})


Yes, run-jetty is function, so everything in the arguments will be evaluated first and what they return will be the argument passed to run-jetty.


So if `(app inject-db-for-middleware) ` returns a handler than it will work


If you pass directly a value to run-jetty, (like passing app instead of #'app), it has no way of knowing if app is modified. #'app is sugar syntax for (var app), a var that points to app. This extra layer of abstraction allows jetty to always access the latest version of app. In your case, the simplest way to achieve that would be something like:

(def my-app (app inject-db-for-middleware))
(jetty/run-jetty #'my-app {:port 3000, :join? false})
When you re-evaluate my-app, jetty will be able to access the latest version without restarting it.

👍 2

That's true, if you're interested in being able to swap the handler without restarting jetty, you have to have a global var.


Thank you a lot