Fork me on GitHub
#beginners
<
2020-10-23
>
Jim Newton09:10:31

There is a note at the very bottom of the https://clojuredocs.org/clojure.core/with-meta. Can someone explain to me what it means. The sentence is not complete, and is confusing.

dumrat09:10:24

Isn't it clear? It basically says that while for other values with-meta has no effect on equality comparison, for functions it does:

(= (with-meta [10 20] {:some :meta}) [10 20]) => true
(defn foo [] "hi")
(= foo foo) => true
(= (with-meta foo {:some-more :meta}) foo) => false

delaguardo09:10:58

(= foo foo) is to compare vars not functions, isn’t it?

Jim Newton09:10:38

I was confused by the sentence fragment in the test.

Jim Newton09:10:03

So a function is equal to itself, but a function with metadata attached is not equal to the original function.

Alex Miller (Clojure team)11:10:50

Functions compare with identity and once you add metadata, they are no longer identical

✔️ 3
Jim Newton11:10:53

are any other objects which are compared for identity also capable of attaching to meta data?

Alex Miller (Clojure team)11:10:34

can't think of any, this is kind of a special case

✔️ 3
Rafał Wyszomirski09:10:11

Hey hello. Sorry if this question was asked before but how can I get the whole response using cljs-ajax? :on-success returns response data only.

Rafał Wyszomirski09:10:02

I'm mostly interested in status and headers.

Rafał Wyszomirski09:10:09

I'm talking specifically about [day8.re-frame/http-fx "0.2.1"] which uses cljs-ajax under the hood

jsn10:10:32

did you try response-format :raw ?

Rafał Wyszomirski11:10:37

Yeah, but I don't think it will change anything, sincie only response body is returned. So in effect, a string is returned instead of JSON

jsn11:10:27

perhaps you could write your own response format then

jsn11:10:59

but yeah, it seems somewhat tedious

😉 3
Rafał Wyszomirski11:10:15

Anyway, thanks for help. I'm curious how others tackle this issue in re-frame/clojurescript though.

jsn11:10:55

No idea; but maybe someone in #clojurescript and/or #re-frame would know something

Jim Newton11:10:17

what's the word to use to emphasize that a computation is not lazy?

gon11:10:36

eagerly ?

Jim Newton11:10:45

I want to write a version of map in my own utils library which does a non-lazy map. similar for mapcat

zilti11:10:35

mapv works eager, afaik. Also, if you want map to be eager, you can wrap it in a doall

Alex Miller (Clojure team)11:10:32

Or use into with a map transducer

Calum Boal12:10:54

Can anyone help me figure out wtf is going wrong here

(defn in?
  "true if coll contains elm"
  [coll elm]
  (some #(= elm %) coll))

(defn first-unused-between [start finish col]
  (if (empty? col) (first-unused-between start finish ["1"]))
  (->> (range start (inc finish))
       (take-while #(in? col (str %1)))
       (last)
       (inc)
       (str)))

(first-unused-between 1 254 ["1"])
That runs fine, but doing (first-unused-between 1 254 []) throws a null pointer exception, even though it should be recursively calling the function with col set to ["1"] if it is passed empty

teodorlu12:10:11

@cgboal521 your if line doesn't do anything; you just if and return the threading expression. Was that your intention?

(if (empty? col) (first-unused-between start finish ["1"]))

Calum Boal12:10:50

I want to call the first-unused-between function with a default value for col if the value passed for col is empty

teodorlu12:10:24

Did you want this, then? (haven't tested)

(defn first-unused-between [start finish col]
  (if (empty? col)
    (first-unused-between start finish ["1"])
    (->> (range start (inc finish))
         (take-while #(in? col (str %1)))
         (last)
         (inc)
         (str))))

Calum Boal12:10:32

Ah okay cool

Calum Boal12:10:37

Yeah so it needs to be inside the if?

teodorlu12:10:00

Yeah, otherwise you just "compute a result from the if, discard it, and do the next thing anyway"

Calum Boal12:10:31

Ahh okay, that makes sense

teodorlu12:10:47

My pleasure :thumbsup:

Endre Bakken Stovner19:10:43

I am getting "Invalid :refer, var foo.bar/baz" does not exist in cljs. The file foo.bar is there and it contains a function baz. How do I even start to debug this error?

andy.fingerhut19:10:04

You actually have a directory named foo.bar ? I suspect that cljs, like clj, expects the namespace foo.bar to be found in a directory bar inside of a directory foo

andy.fingerhut19:10:40

Or rather, in a file named bar.cljs inside of a directory named foo

Endre Bakken Stovner19:10:41

No sorry. I have a directory foo, with a file bar.cljs . These are both in the same folder as core.cljs. This was a reply to reply 1 btw XD

andy.fingerhut19:10:30

Have you attempted to delete any/all caches of compiler output from previous cljs compiler runs you have made, and then run the compiler again?

Endre Bakken Stovner19:10:54

I tried running shadow-cljs compile again. I'll try to delete all js-files in target/cljsbuild too.

Endre Bakken Stovner19:10:39

Did not work 😕 I must be doing something stupid.

andy.fingerhut19:10:05

What does the complete ns form look like inside of your file foo/core.cljs ?

andy.fingerhut19:10:39

And the function baz isn't commented out in some way? Or perhaps it is defined after some point where there is a compiler error in the file foo/bar.cljs, so the compiler never gets that far to see baz ?

Endre Bakken Stovner19:10:42

(ns ouija.core
  (:require
    [day8.re-frame.http-fx]
    [reagent.dom :as rdom]
    [reagent.core :as r]
    [re-frame.core :as rf]
    [goog.events :as events]
    [goog.history.EventType :as HistoryEventType]
    [markdown.core :refer [md->html]]
    [ouija.ajax :as ajax]
    [ouija.events]
    [ouija.highlight :refer [highlight] ; offending line
    [reitit.core :as reitit]
    [reitit.frontend.easy :as rfe]
    [clojure.string :as string]
    [com.rpl.specter :refer [MAP-VALS]])
  (:import goog.History))

andy.fingerhut19:10:54

If you are willing to try an experiment where highlight is the first function defined in ouija/highlight.cljs, that may help determine whether there is some other error in ouija/highlight.cljs that could be causing trouble.

Endre Bakken Stovner19:10:07

It is just a toy project. I think you should just be able to git clone and compile

Endre Bakken Stovner19:10:23

lein shadow watch app

Endre Bakken Stovner19:10:26

I tried adding the line (defn highlight [])to the top of the file. Did not change anything.

seancorfield19:10:11

It might well be due to you having highlight.clj and highlight.cljs in the clj tree as well as highlight.cljs in the cljs tree?

seancorfield19:10:52

> find . -name 'highlight.*'
./src/clj/ouija/highlight.clj
./src/clj/ouija/highlight.cljs
./src/cljs/ouija/highlight.cljs

Endre Bakken Stovner19:10:55

Oh, wow! Nice catch

Endre Bakken Stovner19:10:57

Now it works 🙂 :thumbsup:

3
Endre Bakken Stovner19:10:20

Thanks to the both of you.

Endre Bakken Stovner20:10:03

In clojurescript I want to read the string "MAP-VALS" and interpret it as com.rpl.specter/MAP-VALS. Is there a way to do so? I could have a hash-map that connects the two, but I was hoping to do it with read-string.

Endre Bakken Stovner20:10:29

If you have required specter, (eval (read-string "MAP-VALS")) will give com.rpm.specter/...

Endre Bakken Stovner20:10:13

But there is no eval in clojurescript...

leif20:10:44

So, probably a silly question, but if #(...) is short for (fn [args ...] (...)), then why is #(let [...] ...) short for (fn [args ...] (let [...] ...), or am I missing something about #(...) (or (let [...] ...))?

herald20:10:25

For #() the argument bindings are implicit, so if you ignore the (fn [args ...] it slides right in.

herald20:10:35

At least that's how I see it

leif20:10:16

@UCW9TUDNK Sure, but that's not the problem here. Its the implicit function application, unless its a let.

leif20:10:24

Oh, its because let is also surrounded by ()....I think.

leif20:10:32

Very odd, thanks btw. 🙂

herald20:10:36

There is no function application though, as #() is a noop (same as (fn []).

herald20:10:56

Yes. I attribute it to lisp macro "magic" [=

hiredman21:10:59

the expression following the # becomes the body of the fn, it is confusing because the parens in #(...) both act as delimiters of the anonymous function, and as part of the expression (...) which becomes the body of the anonymous function

hiredman21:10:05

another way to think of it is # starts an anonymous function, where the form that follows it is the body, but that form has to be a list (is wrapped in parens)

hiredman21:10:32

another way to understand it would be figuring out which parenthesis correspond to each other in the #(...) syntax and the (fn [...] (...)) syntax

hiredman21:10:12

#(...) => (fn [...] (...))

hiredman21:10:27

not sure how well that formatting emphasis comes through

hiredman21:10:33

#(let [...] ...) => (fn [...] (let [...] ...))

hiredman21:10:49

mechanically it is the same thing

seancorfield21:10:49

That's probably one of the best explanations I've heard for it, to be honest!

seancorfield21:10:32

#parenthesized-thing => (fn [...] parenthesized-thing) or #`(...)` => (fn [...] (...))

leif22:10:41

Ya, I get it. Thanks. 🙂

leif22:10:15

I'm just a little more used to Racket macros where that sort of thing is less common. 🙂

leif22:10:17

Anyway, thanks.