Hi, can I use fdef
for spec on defmulti
? I am using it in clojurescript and after hotreload in figwheel I got this message:
Uncaught Error: No protocol method IMultiFn.-add-method defined for type function
is it a bug or I am using spec wrong?
(defmulti ->api-event
"Map form outputs into api event."
{:arglists '([form-id form-values])}
(fn [form-id _form-values]
form-id))
(s/fdef ->api-event
:args (s/cat :form-id keyword?
:form-values (s/map-of keyword? any?))
:ret (s/nilable ::types/api-resource))
When I remove fdef
part, error will not throw.It’s not supported
You can spec the dispatch function itself, or you can wrap it in a function to spec it
Thanks!🙏
Hi, I would like to resolve the dependency graph of a set of maven root dependencies. The things I've found in clojureland for this are tools.deps.alpha and pomegranate. I would however only like to resolve the graph (i.e. load the pom:s), but not download it (i.e. the jars) and also I would like for the process to be multi-threaded as large dependency graphs otherwise get time consuming. From my understanding tools.deps.alpha does multithreading but not the "lazy loading" and pomegranate is the other way around (i.e. can skip downloading but not multi threaded). Any pointers to libs or perhaps to how I should use the existing ones to accomplish this much appreciated. Started doing the multi threading part myself but implementing all the nuances of pom parsing (parents, variables, etc) is some work. End result should be a tree of [group artifact-name version] tuples in some suitable format.
it is possible to tactically use parts of tools.deps to just traverse the pom / dependency structure, but the parallel download is buried in the dep expansion so you'd need to build that yourself
in particular, the individual node step in the middle can be done with something like
@alexmiller ok that makes sense. I'll take a look at the source. The problem I am trying to solve is that we run into these massive dependency graphs for large projects and they often have either internal version collisions or when they don't, they make it impossible to upgrade anything in a controlled manner because it's hard to find a non-colliding upgrade path. I'm looking to build a tool to programmatically explore the version trees. Surprised something like this does not already exist since semantic versioning is what it is.
(clojure.tools.deps.alpha.extensions/coord-deps 'org.clojure/clojure {:mvn/version "1.10.2"} :mvn {:mvn/repos clojure.tools.deps.alpha.util.maven/standard-repos})
and this is not clojure specific, just the state of the java eco system I think
@alexmiller thank you, that looks promising, just ran it in a repl.
it's on you to avoid cycles, ignore exclusions, etc etc of course :)
yeah, there is that
there are facilities for comparing versions and things like that - some of that is exposed ctdae/compare-versions
etc
@alexmiller but the above handles things like boms, parents, pom variable expansion etc?
handles must cases properly understanding things like parents, pom variables, etc (uses the appropriate maven apis). I think we've had issues with boms in the past, so I'm not positive about that part.
@alexmiller ok thanks again, that helps.
if you have followups, #tools-deps is a thing
ok will do
Hi guys, I'm trying to understand how this two calls to String/valueOf are producing different behavior
(String/valueOf (first nil)) "null"
vs
(String/valueOf nil) Execution error (NullPointerException) at java.lang.String/<init> (String.java:166).
I presume inferred type
first one is probably String.valueOf(Object), second one maybe String.valueOf(char[]) ?
> if the argument is null, then a string equal to "null"; otherwise, the value of obj.toString() is returned. for the Object overload
yup, I understand that, but I'm having trouble to understand why nil is assumed to be char[] instead of Object
I don't think it's assumed, you're just getting first match from the reflector
so somewhat arbitrary
but why then takes another match when given (first nil)
?
(first nil) is a function that returns an Object
and there is a valueOf(Object), so that's a match
in the latter case, null means no type information so anything could match
and then it defaults to the first match based on arity?
yeah
user=> (defn value-of [^Object o] (String/valueOf o))
#'user/value-of
user=> (value-of nil)
"null"
strange even java is doing same
public class Test {
public String foo(Object o) {
return System.currentTimeMillis() + "as Object";
}
public String foo(char[] c) {
return System.currentTimeMillis() + "as char[]";
}
public static void main(String[] args) {
Test test = new Test();
System.out.println(test.foo(null));
}
}
thanks for feedback, I'm still a bit confused but will try to understand
Is there a reason why the edn spec hasn't been updated with the ##NaN ##Inf and ##-Inf tagged literals introduced in clojure even though Rich Hickey was in favour of doing so back in 2014? Relavant thread https://github.com/edn-format/edn/issues/2