Fork me on GitHub
#beginners
<
2021-12-11
>
Cnly01:12:45

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?

hiredman02:12:07

keys is (partial map key)

Cnly11:12:47

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

Cnly11:12:57

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.

andy.fingerhut12:12:42

If you have a short sequence of expressions one can type into a REPL to reproduce that, it would help.

andy.fingerhut12:12:29

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:

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

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

andy.fingerhut13:12:57

Maybe not a good test, because

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

andy.fingerhut13:12:45

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

andy.fingerhut14:12:47

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.

andy.fingerhut14:12:23

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:

andy.fingerhut14:12:45

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

andy.fingerhut14:12:49

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)

andy.fingerhut14:12:07

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
  [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.

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.

walterl21:12:39

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