Fork me on GitHub
#clojure
<
2021-06-21
>
anisoptera02:06:38

@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

anisoptera02:06:48

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

emccue03:06:18

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

anisoptera03:06:58

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

anisoptera03:06:27

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

vncz13:06:48

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?

Alex Miller (Clojure team)13:06:51

easy to parse either way via kwargs

Alex Miller (Clojure team)13:06:15

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

vncz14:06:08

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?

vncz14:06:17

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

Alex Miller (Clojure team)14:06:08

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

Alex Miller (Clojure team)14:06:46

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

vncz14:06:02

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

Alex Miller (Clojure team)14:06:40

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

vncz14:06:36

Yeah I guess that’s what I did not know

vncz14:06:48

Keys destructuring works also on non maps?

Alex Miller (Clojure team)14:06:44

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

vncz14:06:28

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

vncz14:06:39

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

Alex Miller (Clojure team)14:06:41

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

vncz14:06:10

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

Alex Miller (Clojure team)14:06:26

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

Alex Miller (Clojure team)14:06:03

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