This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-11-30
Channels
- # announcements (4)
- # babashka (3)
- # beginners (5)
- # calva (20)
- # cider (12)
- # clj-kondo (7)
- # cljs-dev (2)
- # clojure (76)
- # clojure-uk (4)
- # clojuredesign-podcast (8)
- # clojurescript (18)
- # clojutre (1)
- # cursive (9)
- # data-science (27)
- # datomic (2)
- # fulcro (32)
- # graalvm (4)
- # jackdaw (5)
- # jobs (2)
- # joker (5)
- # lumo (20)
- # off-topic (18)
- # pathom (3)
- # shadow-cljs (18)
- # sql (5)
- # tools-deps (1)
- # vim (11)
clojure.edn/read-string
uses *data-readers*
right? I'm getting "No reader function for tag time/zoned-date-time" even though time/zoned-date-time => #'time-literals.data-readers/zoned-date-time
is in *data-readers*
@robert.mather.rmm you can provide data readers as an optional argument, otherwise only the default data readers are used, according to the doc string of edn/read
I'm trying to figure out if it uses the default readers vs. the ones explicitly passed, not certain yet https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/EdnReader.java
fwiw that java file has no reference to *data-readers*
that it would grab, and the value also isn't passed in by clojure.edn/read
Thanks. Passing explicitly via the :readers
opt worked. I was just surprised *data-readers*
` wasn't used. What's that for, if not the built-in reading mechanisms? Does it only get used for core/read
not edn/read
?
precisely that
see notes here https://clojuredocs.org/clojure.edn/read and here https://clojuredocs.org/clojure.core/*data-readers*
I think this summarizes the behaviors and workaround
(ins)user=> (println (slurp "src/data_readers.clj"))
{foo/bar clojure.core/set}
nil
(cmd)user=> #foo/bar[1 2 3]
#{1 3 2}
(ins)user=> (read-string "#foo/bar[4 5 6]")
#{4 6 5}
(cmd)user=> (clojure.edn/read-string "#foo/bar[1 2 3]")
Execution error at user/eval154 (REPL:1).
No reader function for tag foo/bar
(cmd)user=> (clojure.edn/read-string {:readers *data-readers*} "#foo/bar[1 2 3]")
#{1 3 2}
clojure-lsp uses org.eclipse.lsp4j and has a single java file
@JsonSegment("clojure")
public class ClojureExtensions {
@JsonRequest
@SuppressWarnings("unchecked")
CompletableFuture<String> dependencyContents(TextDocumentIdentifier documentUri) {
IFn require = Clojure.var("clojure.core", "require");
require.invoke(Clojure.read("clojure-lsp.main"));
IFn extension = Clojure.var("clojure-lsp.main", "extension");
return (CompletableFuture<String>) extension.invoke("dependencyContents", documentUri);
this causes in target/
├── classes
│ ├── clojure_lsp
│ │ └── ClojureExtensions.class
│ └── org
│ └── eclipse
│ └── lsp4j
│ └── TextDocumentIdentifier.class
which causes a problem. Since the lsp4j jar is signed, this other class is not signed and the jvm rejects this as a security exception:cause class "org.eclipse.lsp4j.TextDocumentIdentifier"'s signer information does not match signer information of other classes in the same package
This problem seems to only happen on java > 8. Can anyone point me in a direction to understand why this TextDocumentIdentifier is being compiled? Removing this class file prevents the security error
i think i have solved it with -implicit:none
as a javac option but i don't know if i'm solving the root issue or solving a symptom
I wonder if there is something in the deps tree for lsp4j that is including the Java source that you could exclude. I have this vague idea that lsp4j is using eclispe's custom Java syntax thing, and the tooling for that somehow ends up including Java source in jars, and then lein's use of the javax tools javac results in a compiler that looks for source anywhere on the classpath, which results in compiling that class. But I don't know for sure about most of that. And I am not sure if that explains why just that one class is compiled.
still digesting what you wrote but yes its using xtend, the sugar over java language
that one class is the only one imported into the java file in lsp. i've been trying other java classes and no other ones end up in the output so your theory is a good starting point for me
another thought. java looks for class files and source files, by default preferring whichever is newer. if the java source file is an artifact due to the sugared language, it might be older than the class file and therefore javac thinks it needs a newer version and compiles it again?
:dependencies [[org.clojure/clojure "1.10.0"]
[jarohen/chord "0.8.1"]
[cljs-ajax "0.8.0"]]
[jarohen/chord "0.8.1"] -> [com.cognitect/transit-clj "0.8.275"]
overrides
[cljs-ajax "0.8.0"] -> [com.cognitect/transit-clj "0.8.309"]
How come order matters and the older version wins? 😲Because lein uses maven's dependency resolution algorithm, and maven is basically first one wins
Alex's recent conj talk goes into this some because the tools.deps.alpha code treats this kind of thing differently
Been using maven for ages. So far, I got away assuming most recent version wins. Thanks @U0NCTKEV8!
Still pretty scary. Wonder what's best practice to make it more explicit. Using a non transitive dep?
Please help me understand why my solution to problem http://www.4clojure.com/problem/39 works in the REPL but fails when pasted on to the site:
(fn f39
[s1 s2]
(-> (zipmap s1 s2)
(seq)
(flatten)))
https://github.com/4clojure/4clojure/blob/develop/src/foreclojure/problems.clj#L196 here's the code for testing user input
https://github.com/4clojure/4clojure/blob/develop/src/foreclojure/data_set.clj#L428 here's the problem definition
Oh great thanks. Interesting but that exactly how i test the function in my REPL user> (= (f39 [1 2 3] [:a :b :c]) '(1 :a 2 :b 3 :c))
That returns true
Just tried the source code of zipmap
(fn [keys vals]
(loop [map {}
ks (seq keys)
vs (seq vals)]
(if (and ks vs)
(recur (assoc map (first ks) (first vs))
(next ks)
(next vs))
(flatten (seq map)))))
No luck. But if I get rid of hash-map here
(fn [keys vals]
(loop [ret []
ks (seq keys)
vs (seq vals)]
(if (and ks vs)
(recur (conj ret (first ks) (first vs))
(next ks)
(next vs))
ret)))
Weird, on the android app, the unit tests pass, but sending to the server errors saying it rejected the solution
I wonder if zipmap isn't allowed but they forgot to mention it as a restriction just like interleave?
> I wonder if zipmap isn't allowed but they forgot to mention it as a restriction just like interleave?
I've tried without zipmap, and it seems like the issue boils down to assoc
with hash-map
But I think the problem is there’s a “flatten” in zipmap which I think might be lazy. Your repl will force evaluation of these (the P in repl) but running on 4clojure doesn’t
(fn [_ _] (flatten (seq (assoc [] 0 1 1 :a 2 2 3 :b 4 3 5 :c))))
This one works for the first test. I think there's no problem with flatten
. But when I introduce a hash-map
with assoc
the test will fail
(fn [_ _] (flatten (seq (assoc {} 1 :a 2 :b 3 :c))))
dan@pop-os:~/projects/clojure$ clj -Sdeps "{:deps {org.clojure/clojure {:mvn/version \"1.4.0\"}}}"
Clojure 1.4.0
user=> (flatten (seq (assoc {} 1 :a 2 :b 3 :c)))
(3 :c 2 :1 :a)
user=>
recent clojures use array-maps for smaller maps under 8 (or 9, forgot whether the cutover is < or <=). So they would be ordered as an implementation detail
if you want to test your solutions on older clojure the above is a good way to do that easily. lots of annoying things like update-in doesn't exist, maybe even update?
is it possible to build a syntax sugar like #:person[:id :name :age]
,just like the prefix for map with data_readers?
hey hol' up, are you the same ghadi from the Charleston functional programming slack channel?
Ahaha I guess this isn't unexpected but it still feels like a small world moment! (I'm the same Cameron rambling on there like a month ago)
I used core.logic to solve http://regexcrossword.com puzzles and wrote up what happened: https://www.lvh.io/posts/solving-regex-crosswords/ -- demo (if you're on linux amd64) here: https://github.com/lvh/regex-crossword/releases/tag/0.1.0
patches welcome for the blog post: https://github.com/lvh/lvh.github.io/blob/source/posts/solving-regex-crosswords.md