beginners

Getting started with Clojure/ClojureScript? Welcome! Also try: https://ask.clojure.org. Check out resources at https://gist.github.com/yogthos/be323be0361c589570a6da4ccc85f58f.
Jim Newton 2020-10-23T09:02:31.396900Z

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.

dumrat 2020-10-23T09:07:24.397Z

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

2020-10-23T09:10:58.397300Z

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

Rafał Wyszomirski 2020-10-23T09:29:11.399Z

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.

Jim Newton 2020-10-23T09:29:38.399100Z

I was confused by the sentence fragment in the test.

Jim Newton 2020-10-23T09:30:03.399300Z

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

Rafał Wyszomirski 2020-10-23T09:31:02.399500Z

I'm mostly interested in status and headers.

Rafał Wyszomirski 2020-10-23T09:36:09.399700Z

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

jsn 2020-10-23T10:49:32.401300Z

did you try response-format :raw ?

Jim Newton 2020-10-23T11:03:17.402700Z

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

gon 2020-10-23T11:03:36.403300Z

eagerly ?

Jim Newton 2020-10-23T11:03:45.403500Z

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

zilti 2020-10-23T11:04:35.404200Z

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

Rafał Wyszomirski 2020-10-23T11:04:37.404300Z

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

jsn 2020-10-23T11:07:27.404500Z

perhaps you could write your own response format then

jsn 2020-10-23T11:07:59.404700Z

but yeah, it seems somewhat tedious

😉 1
Rafał Wyszomirski 2020-10-23T11:14:15.405Z

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

jsn 2020-10-23T11:18:55.405400Z

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

alexmiller 2020-10-23T11:24:32.406Z

Or use into with a map transducer

alexmiller 2020-10-23T11:24:58.406400Z

Or mapcat etc

alexmiller 2020-10-23T11:26:50.407800Z

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

✔️ 1
Jim Newton 2020-10-23T11:45:53.408300Z

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

alexmiller 2020-10-23T11:50:34.408800Z

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

✔️ 1
Calum Boal 2020-10-23T12:44:54.410300Z

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

teodorlu 2020-10-23T12:47:11.411Z

@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 Boal 2020-10-23T12:47:50.411700Z

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

teodorlu 2020-10-23T12:48:24.412100Z

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 Boal 2020-10-23T12:48:32.412400Z

Ah okay cool

Calum Boal 2020-10-23T12:48:37.412600Z

Yeah so it needs to be inside the if?

teodorlu 2020-10-23T12:49:00.413Z

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

Calum Boal 2020-10-23T12:49:31.413400Z

Ahh okay, that makes sense

Calum Boal 2020-10-23T12:49:35.413600Z

Thank you

teodorlu 2020-10-23T12:49:47.413800Z

My pleasure :thumbsup:

Endre Bakken Stovner 2020-10-23T19:16:43.417900Z

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?

2020-10-23T19:18:04.418400Z

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

2020-10-23T19:18:40.418600Z

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

Endre Bakken Stovner 2020-10-23T19:18:41.418800Z

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

2020-10-23T19:19:39.419200Z

Understood.

2020-10-23T19:20:30.419400Z

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 Stovner 2020-10-23T19:20:54.419600Z

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

Endre Bakken Stovner 2020-10-23T19:24:39.419900Z

Did not work 😕 I must be doing something stupid.

2020-10-23T19:25:05.420100Z

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

2020-10-23T19:27:39.420400Z

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 Stovner 2020-10-23T19:27:42.420600Z

(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))

Endre Bakken Stovner 2020-10-23T19:29:41.420800Z

https://github.com/endrebak/ouija/

2020-10-23T19:29:54.421Z

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 Stovner 2020-10-23T19:30:07.421200Z

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

Endre Bakken Stovner 2020-10-23T19:30:23.421500Z

lein shadow watch app

Endre Bakken Stovner 2020-10-23T19:30:30.421700Z

I will experiment

Endre Bakken Stovner 2020-10-23T19:33:26.422Z

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

seancorfield 2020-10-23T19:35:11.422200Z

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?

seancorfield 2020-10-23T19:35:52.422400Z

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

Endre Bakken Stovner 2020-10-23T19:35:55.422600Z

Oh, wow! Nice catch

Endre Bakken Stovner 2020-10-23T19:38:57.422800Z

Now it works 🙂 :thumbsup:

1
Endre Bakken Stovner 2020-10-23T19:40:20.423200Z

Thanks to the both of you.

Endre Bakken Stovner 2020-10-23T20:11:03.426600Z

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 Stovner 2020-10-23T20:22:29.427100Z

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

2020-10-23T20:28:44.429300Z

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 [...] ...))?

uosl 2020-10-23T20:32:25.429400Z

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

uosl 2020-10-23T20:32:35.429600Z

At least that's how I see it

Endre Bakken Stovner 2020-10-23T20:33:13.429800Z

But there is no eval in clojurescript...

2020-10-23T20:34:16.430Z

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

2020-10-23T20:36:24.430300Z

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

2020-10-23T20:36:32.430500Z

Very odd, thanks btw. 🙂

uosl 2020-10-23T20:36:36.430700Z

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

uosl 2020-10-23T20:36:56.430900Z

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

Endre Bakken Stovner 2020-10-23T20:38:07.431200Z

There is resolve: https://clojuredocs.org/clojure.core/resolve huzzah!

2020-10-23T21:01:59.431600Z

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

2020-10-23T21:03:05.431800Z

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)

2020-10-23T21:06:32.432100Z

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

2020-10-23T21:08:12.432400Z

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

2020-10-23T21:08:27.432600Z

not sure how well that formatting emphasis comes through

2020-10-23T21:09:33.432800Z

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

2020-10-23T21:09:49.433Z

mechanically it is the same thing

seancorfield 2020-10-23T21:41:49.433200Z

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

seancorfield 2020-10-23T21:42:32.433400Z

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

2020-10-23T22:50:41.435400Z

Ya, I get it. Thanks. 🙂

2020-10-23T22:51:15.435800Z

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

2020-10-23T22:51:17.436Z

Anyway, thanks.