Fork me on GitHub

I found this example that keys works not only on maps. Why is this under the hood?


keys is (partial map key)


That would be easier to understand, but how did you know?


The source code is (. clojure.lang.RT (keys map))

Quentin Le Guennec11:12:54

Is a tap function added with add-tap supposed to see the metadata of the tapped value?

Quentin Le Guennec11:12:45

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?

Quentin Le Guennec12:12:50

@U0CMVHBL2 yep:

  (defn tap-internal [value]
    (println (meta value)))

  (add-tap tap-internal)
  (tap> ^{:test "meta"} (range 10)))


Maybe not a good test, because

user=> (meta ^{:foo 5} (range 10))


Try instead (tap> (with-meta (range 10) {:test "meta"}))

Quentin Le Guennec13:12:45

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.

Quentin Le Guennec14:12:31

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
[0 1 2 3 4]
user=> (meta v1)
{:foo "x"}
user=> (def v2 ^{:foo "x"} (vec (range 5)))
user=> v2
[0 1 2 3 4]
user=> (meta v2)


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.

👍 1
Sky Leite17:12:16

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
  {:status 200
   :body "Hello!"})

(defn -dev-main
  (jetty/run-jetty handler
    {:port 4000 :join? false}))

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.

Sky Leite18:12:38

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.

Sky Leite00:12:08

I don't think that's it, as the server was still running. I'd get an empty response with curl / wget, but the server was definitely reachable