clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
2021-06-21T02:42:38.298600Z

@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

2021-06-21T02:43:48.299400Z

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

emccue 2021-06-21T03:12:18.299800Z

if this is for an open source thing i'd be curious to see the code

2021-06-21T03:12:58.300100Z

when i’m actually done with it i’ll post it 🙂

2021-06-21T03:13:27.300600Z

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

vncz 2021-06-21T13:56:48.305800Z

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?

alexmiller 2021-06-21T13:57:51.306200Z

easy to parse either way via kwargs

alexmiller 2021-06-21T13:59:15.307200Z

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

vncz 2021-06-21T14:02:08.309Z

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?

vncz 2021-06-21T14:02:17.309300Z

(not a critique here, I’m just trying to understand)

alexmiller 2021-06-21T14:03:08.310Z

no, that's already covered at calling by kwarg destructuring and in spec with s/keys*

alexmiller 2021-06-21T14:03:46.310700Z

they are both equally easy (and in 1.11, actually literally the same)

vncz 2021-06-21T14:04:02.311100Z

Hmm I’ll take a look at the source code then, I guess I am missing something

alexmiller 2021-06-21T14:05:40.312Z

functions/macros defined like (defn foo [& {:keys [a b]}] ... ) can be invoked with (foo :a 1 :b 2)

vncz 2021-06-21T14:06:36.312300Z

Yeah I guess that’s what I did not know

vncz 2021-06-21T14:06:48.312800Z

Keys destructuring works also on non maps?

alexmiller 2021-06-21T14:07:44.313200Z

in this special case, you can destructure the "rest" of the args (a sequence) as if it were a map

vncz 2021-06-21T14:09:28.314200Z

Oh ok now I see, I completely missed that special form part

vncz 2021-06-21T14:09:39.314700Z

Ok that makes a lot more sense now, thanks @alexmiller

alexmiller 2021-06-21T14:09:41.314800Z

the new thing that has been added in 1.11.0-alpha1 is that you can also supply a trailing map for kwargs

vncz 2021-06-21T14:10:10.315400Z

…as in just throw a map as kwargs and it will automatically use it to supply the arguments?

alexmiller 2021-06-21T14:10:26.316Z

so (foo {:a 1 :b 2}) will literally be treated the same as (foo :a 1 :b 2)

vncz 2021-06-21T14:10:32.316300Z

Got it

alexmiller 2021-06-21T14:11:03.316700Z

but also (foo :a 1 {:b 2}) for some of both

vncz 2021-06-21T14:12:53.317300Z

Cool. Thanks @alexmiller