This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
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?
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
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.
Is there a primitive operation that allows rotation of a vector?
; Left rotate once
[1 2 3] => [2 3 1]
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
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...
(conj vector single-element-vector) does not work how I would have expected, though. End up with something like [1 2 3 (4)]
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 ❤️
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 trying to use clj and cljs in a monorepo and try to follow oakes' repo https://github.com/oakes/full-stack-clj-example
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 https://github.com/practicalli/clojure-deps-edn 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:
:repl/nrepl
{:extra-deps {nrepl/nrepl {:mvn/version "0.8.3"}}
:main-opts ["-m" "nrepl.cmdline"]}
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: 127.0.0.1</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
Yes but I am getting 4. I want 6
❯ 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: 127.0.0.1</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.
::1 dev lo proto kernel metric 256 pref medium fe80::/64 dev enp0s3 proto kernel metric 100 pref medium
http://localhost:3000 like this?
PING localhost (127.0.0.1) 56(84) bytes of data. 64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.016 ms 64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.019 ms 64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.034 ms 64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.017 ms 64 bytes from localhost (127.0.0.1): icmp_seq=5 ttl=64 time=0.014 ms 64 bytes from localhost (127.0.0.1): icmp_seq=6 ttl=64 time=0.041 ms 64 bytes from localhost (127.0.0.1): icmp_seq=7 ttl=64 time=0.022 ms 64 bytes from localhost (127.0.0.1): icmp_seq=8 ttl=64 time=0.025 ms 64 bytes from localhost (127.0.0.1): icmp_seq=9 ttl=64 time=0.041 ms
@UP82LQR9N oh good point lemme check...
@UP82LQR9N the URL I use in the browser is: http://localhost:3000 Is that somehow limited to ipv4?
Mine is identical
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.
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 0.0.0.0.3.111
sometimes I use lots of dots in my version numbers 😄
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?
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?
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
@U7ERLH6JX no worries
Hi all, I'm trying to use eastwood using the practicalli edn (https://github.com/practicalli/clojure-deps-edn#lint-tools) 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 aliasI 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.
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.