@emccue thanks again, i really like how the shape of this looks, you basically gave me the push i needed to throw out the contract abstraction web3j had entirely and it’s so much better now
i can just auto-select a method by the parameters you pass. there’s validation underneath so if you pass params that don’t make sense for any of the methods in the abi it just rejects it when you try to encode the calldata
if this is for an open source thing i'd be curious to see the code
when i’m actually done with it i’ll post it 🙂
basically what i’ve wanted is something that lets me hack around with this stuff in the same way that ethersjs does, but, you know, in a good language
Question/curiosity: what is the rationale for spec’s keys function to be like this: (s/keys :req [] :req-un)
? Why not using a map? (s/keys { :req [] :req-un []})
?
Doesn’t the first approach complicate the code a bit since they have to guess the parameter order and make sure it’s correct and stuff like that?
easy to parse either way via kwargs
actually in 1.11, you will be able to pass a trailing map to a kwarg-style function, so actually both should work with literally the same existing code
Doesn’t that pose the burden to validate the order of the arguments? For instance, you would need to spec the function to make sure you don’t do weird stuff such as (s/keys [] :req :req-un)
By using a map it would be way easier, or not?
(not a critique here, I’m just trying to understand)
no, that's already covered at calling by kwarg destructuring and in spec with s/keys*
they are both equally easy (and in 1.11, actually literally the same)
Hmm I’ll take a look at the source code then, I guess I am missing something
functions/macros defined like (defn foo [& {:keys [a b]}] ... )
can be invoked with (foo :a 1 :b 2)
Yeah I guess that’s what I did not know
Keys destructuring works also on non maps?
in this special case, you can destructure the "rest" of the args (a sequence) as if it were a map
https://clojure.org/reference/special_forms#keyword-arguments
Oh ok now I see, I completely missed that special form part
Ok that makes a lot more sense now, thanks @alexmiller
the new thing that has been added in 1.11.0-alpha1 is that you can also supply a trailing map for kwargs
…as in just throw a map as kwargs and it will automatically use it to supply the arguments?
so (foo {:a 1 :b 2})
will literally be treated the same as (foo :a 1 :b 2)
Got it
but also (foo :a 1 {:b 2})
for some of both
Cool. Thanks @alexmiller