This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-08-08
Channels
- # announcements (1)
- # babashka (18)
- # beginners (32)
- # calva (3)
- # chlorine-clover (4)
- # cider (14)
- # clj-commons (24)
- # clj-kondo (1)
- # clojure (34)
- # clojure-europe (4)
- # clojure-filipino (1)
- # clojure-uk (4)
- # clojuredesign-podcast (2)
- # clojurescript (6)
- # conjure (3)
- # core-async (2)
- # datahike (1)
- # datomic (3)
- # emacs (3)
- # esprit (20)
- # fulcro (4)
- # graalvm (11)
- # helix (13)
- # honeysql (4)
- # jobs (1)
- # lumo (1)
- # observability (4)
- # off-topic (11)
- # other-lisps (6)
- # pathom (6)
- # re-frame (13)
- # reagent (1)
- # reitit (1)
- # shadow-cljs (26)
- # web-security (2)
- # xtdb (10)
I want to get a seq of vectors from two seqs: "items" and "hotkeys".
map vector items hotkeys
almost does the job, but "items" might have more elements than "hotkeys". So I want the result of (thisfunc [1 2 3] "qw")
to be ([1 "q"] [2 "w"] [3 nil])
I came up with this, but there's probably a nicer way..
(defn tmp [s1 s2]
(let [cmp (compare (count s1) (count s2))
s1 (if (< cmp 0) (concat s1 (repeat nil)) s1)
s2 (if (> cmp 0) (concat s2 (repeat nil)) s2)]
(map vector s1 s2)))
(defn thisfunc [s1 s2] (map vector s1 (concat (map str s2) (repeat nil))))
seems to work.
(defn f [& seqs]
(let [cnt (apply max (map count seqs))
seqs (map #(concat % (repeat nil)) seqs)]
(take cnt (apply map vector seqs))))
thank you guys!
Again I don't understand the namespacing of symbols referring to records (defined by defrecord
). I have a record defined in a namespace as follows:
(ns clojure-rte.bdd
"Definition of Bdd."
(:require [clojure-rte.cl-compat :refer [cl-cond]]
[clojure-rte.util :refer [fixed-point member group-by-mapped print-vals]]
[clojure-rte.type :as ty]
[clojure.set :refer [union difference intersection]]
))
(defrecord Bdd
[label positive negative])
and I also have a test case defined as follows
(ns clojure-rte.bdd-test
(:require [clojure-rte.bdd :refer :all]
[clojure.test :refer :all]))
(deftest t-typep
(testing "bdd and-not"
(with-bdd-hash []
(is (bdd-typep 42 (Bdd. 'Long)))
(is (not (bdd-typep 42 (Bdd. 'String))))
(is (not (bdd-typep "42" (Bdd. 'Long))))
(is (bdd-typep "42" (Bdd. 'String)))
(is (bdd-typep 42 (bdd-or (Bdd. 'Long)
(Bdd. 'String))))
(is (bdd-typep "hello" (bdd-or (Bdd. 'Long)
(Bdd. 'String))))
(is (bdd-typep 42 (bdd-and-not (Bdd. 'Long)
(Bdd. 'String))))
(is (not (bdd-typep "hello" (bdd-not (Bdd. 'Long)
(Bdd. 'String)))))
(is (not (bdd-typep 42 (bdd-and-not (Bdd. 'String)
(Bdd. 'Long)))))
(is (bdd-typep "hello" (bdd-and-not (Bdd. 'String)
(Bdd. 'Long)))))))
Both from the shell lein test
and also if I restart cider and run the tests I get the following error.
clojure-rte.core> (test/run-tests 'clojure-rte.bdd-test)
Execution error at clojure.test/test-ns (test.clj:743).
No namespace: clojure-rte.bdd-test found
Syntax error (IllegalArgumentException) compiling new at (bdd_test.clj:77:25).
Unable to resolve classname: Bdd
It seems the ?parser? cannot understand the Bdd.
syntax.
Can someone tell me what's wrong?I've discovered something more I don't understand.
If the current ns is that in which the Bdd
record is defined, clojure-rte.bdd
, then I can evaluate Bdd
in the repl to obtain clojure_rte.bdd.Bdd
which is an object of type java.lang.Class
clojure-rte.bdd-test> (in-ns 'clojure-rte.bdd)
#namespace[clojure-rte.bdd]
clojure-rte.bdd> Bdd
clojure_rte.bdd.Bdd
clojure-rte.bdd> (type Bdd)
java.lang.Class
clojure-rte.bdd>
However, if the current name space is something else, a ns which requires clojure-rte.bdd
(ns clojure-rte.bdd-test
(:require [clojure-rte.bdd :refer :all]
[clojure.test :refer :all]))
Then Bdd
cannot be evaluated at the repl, and (resolve 'Bdd)
returns nil
clojure-rte.bdd> (in-ns 'clojure-rte.bdd-test)
#namespace[clojure-rte.bdd-test]
clojure-rte.bdd-test> (resolve 'Bdd)
nil
clojure-rte.bdd-test> Bdd
Syntax error compiling at (clojure-rte:localhost:61915(clj)*:1:15115).
Unable to resolve symbol: Bdd in this context
clojure-rte.bdd-test>
however, the fully qualified name is resolvable
clojure-rte.bdd-test> clojure_rte.bdd.Bdd
clojure_rte.bdd.Bdd
clojure-rte.bdd-test> (type clojure_rte.bdd.Bdd)
java.lang.Class
clojure-rte.bdd-test>
Perhaps it is the case that (ns clojure-rte.bdd-test (:require [clojure-rte.bdd :refer :all]))
does not import record names into the namespace?
Since this is a lot of text, I'll copy it to clojureverse. https://clojureverse.org/t/failed-to-import-record-names/6365
To pull in all bindings from one ns to another, use ‘(:use <ns>)’ inside your ns form, instead of ‘:require’ for that ns. Pulling everything in is not recommended generally of course, but may make sense for a test namespace to pull in the implementation namespace.
require does not import class names, you can use :import
for that, or even better use the auto generated ->Bdd
function that clojure creates instead of the class constructor
Can someone help me understand this error message? Why is it complaining about java.util.concurrent.Future
?
clojure-rte.bdd-test> (def ^:dynamic *xyzzy* false)
#'clojure-rte.bdd-test/*xyzzy*
clojure-rte.bdd-test> (map? @*xyzzy*)
Execution error (ClassCastException) at clojure-rte.bdd-test/eval15290 (form-init5713417271367683958.clj:26770).
class java.lang.Boolean cannot be cast to class java.util.concurrent.Future (java.lang.Boolean and java.util.concurrent.Future are in module java.base of loader 'bootstrap')
clojure-rte.bdd-test>
I get the same error from @false
@
is a reader macro for deref
. false
is a boolean and can not be deref:ed, hence the error
more info here: https://clojuredocs.org/clojure.core/deref
is there a predicate for deciding whether something is @ compatible? I notice the warning on atom?
which says it is not a function for deciding if something has been returned from atom
you can ask via instance?
if the object is a clojure.lang.IDeref
or java.util.concurrent.Future
- those are the two supertypes (your perplexing error is because the second, fallback case failed)
is there a %something I can use in (format ...)
which will cause the object to be printed with print-method
rather than printing with its default print?
(defmethod print-method Bdd [bdd w]
(.write w (format "#<Bdd %s %s %s>" (:label bdd) (:positive bdd) (:negative bdd))))
this is my print-method
but when (:positive bdd)
is another object of the same type, it prints as #<Bdd Short true clojure_rte.bdd.Bdd@80ba1805>
rather than making a recursive call to print-method
If I use cl-format, apparently it works with ~A (as in Common-Lisp)
(defmethod print-method Bdd [bdd w]
(.write w (cl-format false "#<Bdd ~A ~A ~A>" (:label bdd) (:positive bdd) (:negative bdd))))
which outputs something like this as requested:
#<Bdd java.io.Serializable true #<Bdd Double true #<Bdd Long true false>>>
Clojure core’s format is just java String’s so probably not
well I have a work-around. But doesn't the java format have a way to trigger the java print-self/to-string
method (whatever it is called, I don't know java).
and is print-method in any way linked to the java to-string
method?
No, it’s clojure’s own multimethod thing iirc. I think you want to look up clojure’s protocols to implement the java toString interface
what is the correct way to determine whether two values are the same object as opposed to simply being = ? I found the function eq
but it has https://clojuredocs.org/clojure.core.logic.fd/eq.
What are the best practices on doing a docker build or equivalent with tool-deps? Should I create a jar and run it in the container?
@dimitar.ouzounoff Overall, I think I've seen most folks end up going with an AOT'd "uber" JAR file run inside Docker via java -jar
.
I think that gives you the fewest moving parts and the most "standard" approach.
(I assume you mean for running an app in production?)