Fork me on GitHub
#clojure
<
2017-06-11
>
hoff11:06:24

is it possible to somehow define a variadic anonymous function? Like (fn ([a] ...) ([a b] ...))?

bronsa11:06:04

exactly like that

hoff11:06:42

i thought i just tried that, hang on

pradyumna11:06:03

(fn [& args] (let [[a b] args] (prn a)))

hoff11:06:11

sorry pradyumna, i got variadic and multi-arity mixed up

donaldball14:06:05

Now that I’m increasingly embracing qualified keywords, I find myself sometimes using keywords from a requirer namespace within its dependent namespaces. For example, I might have a foo.client namespace with my public api, and foo.client.impl on which it depends with implementation details. Having been trained by the clojure single-pass compiler, it feels weird to use :foo.client/key within the impl ns, but I can’t tell if it’s good or bad design, or just a different aesthetic to which I need to get accustomed.

noisesmith14:06:36

@donaldball this is not specific to named keywords, but the pattern I find useful is an abstract namespace (describing protocols and data etc.) an implementation namespace requiring the abstract namespace and making concrete the things the abstract on defines, and an app namespace that does everything in terms of the abstract namespace's functions / datatypes except for a single line construction of sometihng from the impl

noisesmith14:06:39

so in terms of that pattern, the data shapes (and thus namespaced keywords) would come from the abstract ns that all the others use

donaldball14:06:06

That has long been my basic approach to namespace design also, but from the user’s point of view, if the namespaced keywords are part of the public contract, they more naturally fall into what you call the app namespace than the abstract namespace.

noisesmith14:06:57

my take on that is that the end user writes the app namespace

noisesmith14:06:26

and they should be using your abstract namespace, for everything but the constructor