Hi Everyone!
Hello, @mrjaba
yo @mrjaba
Hi :simple_smile:
Is there a way to write a macro which would expand to two adjacent constructs?
e.g. if it was in a {} and you called it, it could expand to both the key and the value?
Actually, a function might be fine, as I can evaluate all the arguments. But I still need to expand it out somehow.. Hmm.
@dominicm: you could try (apply hash-map your-stuff)
@moxaj: For sure, not the best example on why. I'm actually trying to expand out 2 arguments of a library, which can be in any number of places, AND need to be mixed with a lot of others.
Basically, I'd want a macro that looked something like this:
(defmacro x
[]
:key :value)
and an example usage:
{:foo :bar
(x)}
and would compile to:
{:foo :bar
:key :value}
@dominicm hmm, maybe (apply assoc ..) ? (apply assoc {:foo bar} [:key :value])
it's only possible to return a valid clojure symbol/form
@moxaj: But I'd also want it to work elsewhere, e.g.
(myfn (x))
=> (myfn :key :value)
@dm3 So I can't return multiple?
no
Shame. Hmpha, I'll have to find another way to do this then.
what exactly is the problem? do you want to have a user write {:x 1, (bar)}
?
@dm3 So, there's a function consuming keys & values as [& {:keys [x y z]}], and I want to expand in a few to cut down on repetition, mostly because the key/value are mixed (as in, the key contains part of the value)
you can call it with (apply your-fn [:x 1, :y 2])
if that helps
I suppose that would allow me to compose them.. yes. I wish this library allowed the call as a hashmap, then I'd just have to merge the two!
@dm3 heh, no apply for me, as the target is a macro, not a fn.
now you see why you shouldn't write even more macros :simple_smile:
I didn't write the original macro, it's actually enlive! I thought I'd have better success than this.
in macros &form
is available
it gives you the enclosing form, eg {}... so you could do this
i've never seen it done, maybe it's bad, but it might be awesome
https://github.com/cgrand/enlive/issues/136 I've opened an issue, hoping someone has something specific to my scenario.
actually i guess it's not possible because of the even-numbered entries the reader requires
defsnippet is actually a very thin macro: https://github.com/cgrand/enlive/blob/be075b124eb8c4e00b271e21ad63b3a8de6ecb87/src/net/cgrand/enlive_html.clj#L618
but snippet
is also a macro..
The macro hole goes deep
And way beyond my comprehension.
But, in general, this is why macros are bad, and you should always provide a form which takes a plain ol' map.
:simple_smile:
I wonder if it's too late for me to just throw out enlive, and use hiccup. Hmm..
Hello there, any reason to still use use
? In brave clojure book, daniel use it but I saw an blog article on 8thlight that use
is now useless since Clojure 1.4 ?
@majenful: Use has been deprecated & replaced pretty much.
Better to use (require '[name.space :refer :all])
I'm surprised it's still in brave clojure.
I may miss a sentence like « just to illustrate, don’t use it », but in my ebook version he speaks about it
"require and use ensure that a namespace exists and is ready to be used, and optionally let you refer and alias the corresponding namespaces. You should use ns to call require and use in your source files. https://gist.github.com/ghoseb/287710/ is a great reference for all the vagaries of using ns."
Ah, it looks like he's opted to cover everything. But the recommended way to import everything from a namespace is now :refer :all
the only time I use use
is at the repl when I'm hacking b/c it's shorter
oh, that is one of my pet peeves. Documentation that uses use
.
hello everybody
i got a coworker trying to get clojure up and running and he seems to be bumping into the issue captured in this gist
lein repl command hitting a ' java.lang.IllegalArgumentException: array element type mismatch' exception
anybody see this before?
@johangrufman: I'm guessing,, it's some bad syntax somewherre
Go back to a known stable state - get the repl working, then load the new code into the repl
that will highlight it
In a new folder, does "lein new app spork; cd spork; lein repl" also cause a java.lang.IllegalArgumentException?
hi all!
Hi @gnejs!
ahoy
Anyone "going" to Clojure Remote?