This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-12-11
Channels
- # adventofcode (42)
- # asami (13)
- # babashka (40)
- # beginners (25)
- # calva (39)
- # cider (18)
- # circleci (6)
- # cljs-dev (3)
- # clojure (39)
- # clojure-europe (16)
- # clojure-norway (9)
- # clojure-uk (2)
- # clojurescript (42)
- # datalevin (4)
- # datomic (23)
- # fulcro (33)
- # jobs (1)
- # malli (26)
- # minecraft (1)
- # off-topic (88)
- # pedestal (3)
- # polylith (8)
- # re-frame (6)
- # remote-jobs (2)
- # shadow-cljs (20)
- # tools-deps (12)
- # xtdb (5)
I found this example https://clojuredocs.org/clojure.core/keys#example-580dc346e4b001179b66bddb that keys
works not only on maps. Why is this under the hood?
https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/RT.java#L620
Is a tap function added with add-tap
supposed to see the metadata of the tapped value?
My tests indicate me that it doesn't, but I find it very surprising.
If you have a short sequence of expressions one can type into a REPL to reproduce that, it would help.
Also, are you trying to print out (meta <some-value>)
inside of your tap function, and it is returning nil
? Or what other evidence are you seeing to indicate that you are not getting metadata on these values?
@U0CMVHBL2 yep:
(do
(defn tap-internal [value]
(println (meta value)))
(add-tap tap-internal)
(tap> ^{:test "meta"} (range 10)))
(prints nil
)
Maybe not a good test, because
user=> (meta ^{:foo 5} (range 10))
nil
Try instead (tap> (with-meta (range 10) {:test "meta"}))
Hmm, can you explain me the reason for this? I thought that was how the ^ reader macro supposed to work
That macro does put metadata on the list (range 10)
, but not on the result of evaluating the expression (range 10)
, which is what is being passed as an argument.
oh I see, that makes sense, thank you.
I am getting results I do not know how to explain off the top of my head when using quoted literal lists, but with vectors these examples might clarify things:
user=> (def v1 ^{:foo "x"} [0 1 2 3 4])
#'user/v1
user=> v1
[0 1 2 3 4]
user=> (meta v1)
{:foo "x"}
user=> (def v2 ^{:foo "x"} (vec (range 5)))
#'user/v2
user=> v2
[0 1 2 3 4]
user=> (meta v2)
nil
The expression whose value is bound to v1
is a literal vector in the source code. The Clojure reader attaches metadata to this literal vector at read time, and when evaluated a literal expression evaluates to itself, so no change in value (or metaata)
The expressoin whose value is bound to v2
is read as a list (vec (range 5))
, and I am pretty sure that the reader should attach metadata to it at read time (not sure how to clearly show this at the REPL at the moment, though -- someone else may know). When that list expression is evaluated, it constructs a vector and returns it, but the vector created by vec
does not have metadata on it.
Hey. I'm trying to start a very basic HTTP server with ring / jetty, but for some reason on Firefox I get the error "The connection was reset" when trying to access it. This is the code I have at the moment:
(ns mc-discord.core
(:require [lambdaisland.witchcraft :as wc]
[ring.adapter.jetty :as jetty]
[compojure.core :refer [defroutes GET]]
[compojure.route :refer [not-found]])
(:import net.luckperms.api.LuckPermsProvider)
(:import io.mokulu.discord.oauth.DiscordOAuth))
(defn handler
[request]
{:status 200
:body "Hello!"})
(defn -dev-main
[]
(jetty/run-jetty handler
{:port 4000 :join? false}))
(-dev-main)
Worth noting that this worked a couple hours ago, but somewhere down the line it stopped working and I've no idea when or why.I managed to get around it by downgrading ring to 1.8.4. Somehow this error only seems to happen on 1.9.2.
Possibly due to :join? false
, causing your -dev-main
fn to complete, and your server to be shut down.
Based on https://github.com/ring-clojure/ring/blob/master/ring-jetty-adapter/src/ring/adapter/jetty.clj#L170 it looks like you want :join? true
with this usage