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.
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
(= foo foo)
is to compare vars not functions, isn’t it?
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.
I was confused by the sentence fragment in the test.
So a function is equal to itself, but a function with metadata attached is not equal to the original function.
I'm mostly interested in status and headers.
I'm talking specifically about [day8.re-frame/http-fx "0.2.1"]
which uses cljs-ajax under the hood
did you try response-format
:raw
?
what's the word to use to emphasize that a computation is not lazy?
eagerly ?
I want to write a version of map
in my own utils library which does a non-lazy map. similar for mapcat
mapv
works eager, afaik. Also, if you want map
to be eager, you can wrap it in a doall
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
perhaps you could write your own response format then
but yeah, it seems somewhat tedious
Anyway, thanks for help. I'm curious how others tackle this issue in re-frame/clojurescript though.
No idea; but maybe someone in #clojurescript and/or #re-frame would know something
Or use into with a map transducer
Or mapcat etc
Functions compare with identity and once you add metadata, they are no longer identical
are any other objects which are compared for identity also capable of attaching to meta data?
can't think of any, this is kind of a special case
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@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"]))
I want to call the first-unused-between function with a default value for col if the value passed for col is empty
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))))
Ah okay cool
Yeah so it needs to be inside the if?
Yeah, otherwise you just "compute a result from the if, discard it, and do the next thing anyway"
Ahh okay, that makes sense
Thank you
My pleasure :thumbsup:
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?
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
Or rather, in a file named bar.cljs
inside of a directory named foo
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
Understood.
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?
I tried running shadow-cljs compile again. I'll try to delete all js-files in target/cljsbuild
too.
Did not work 😕 I must be doing something stupid.
What does the complete ns
form look like inside of your file foo/core.cljs
?
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
?
(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))
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.
It is just a toy project. I think you should just be able to git clone and compile
lein shadow watch app
I will experiment
I tried adding the line (defn highlight [])
to the top of the file. Did not change anything.
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?
> find . -name 'highlight.*'
./src/clj/ouija/highlight.clj
./src/clj/ouija/highlight.cljs
./src/cljs/ouija/highlight.cljs
Oh, wow! Nice catch
Now it works 🙂 :thumbsup:
Thanks to the both of you.
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
.
If you have required specter, (eval (read-string "MAP-VALS"))
will give com.rpm.specter/...
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 [...] ...)
)?
For #()
the argument bindings are implicit, so if you ignore the (fn [args ...]
it slides right in.
At least that's how I see it
But there is no eval in clojurescript...
@regen Sure, but that's not the problem here. Its the implicit function application, unless its a let
.
Oh, its because let
is also surrounded by ()
....I think.
Very odd, thanks btw. 🙂
There is no function application though, as #()
is a noop (same as (fn [])
.
Yes. I attribute it to lisp macro "magic" [=
There is resolve: https://clojuredocs.org/clojure.core/resolve huzzah!
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
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)
another way to understand it would be figuring out which parenthesis correspond to each other in the #(...)
syntax and the (fn [...] (...))
syntax
#(...) => (fn [...] (...))
not sure how well that formatting emphasis comes through
#(let [...] ...) => (fn [...] (let [...] ...))
mechanically it is the same thing
That's probably one of the best explanations I've heard for it, to be honest!
#parenthesized-thing
=> (fn [...] parenthesized-thing)
or #`(...)` => (fn [...] (...)
)
Ya, I get it. Thanks. 🙂
I'm just a little more used to Racket macros where that sort of thing is less common. 🙂
Anyway, thanks.