Fork me on GitHub
#admin-announcements
<
2015-11-06
>
mrjaba09:11:45

Hi Everyone!

ian09:11:01

Hello, @mrjaba

dominicm13:11:16

Is there a way to write a macro which would expand to two adjacent constructs?

dominicm13:11:47

e.g. if it was in a {} and you called it, it could expand to both the key and the value?

dominicm13:11:02

Actually, a function might be fine, as I can evaluate all the arguments. But I still need to expand it out somehow.. Hmm.

moxaj13:11:13

@dominicm: you could try (apply hash-map your-stuff)

dominicm13:11:35

@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.

dominicm13:11:58

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}

moxaj13:11:46

@dominicm hmm, maybe (apply assoc ..) ? (apply assoc {:foo bar} [:key :value])

dm313:11:58

it's only possible to return a valid clojure symbol/form

dominicm13:11:12

@moxaj: But I'd also want it to work elsewhere, e.g. (myfn (x)) => (myfn :key :value)

dominicm13:11:32

@dm3 So I can't return multiple?

dominicm13:11:24

Shame. Hmpha, I'll have to find another way to do this then.

dm313:11:56

what exactly is the problem? do you want to have a user write {:x 1, (bar)}?

dominicm13:11:11

@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)

dm313:11:12

you can call it with (apply your-fn [:x 1, :y 2]) if that helps

dominicm13:11:53

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!

dominicm14:11:25

@dm3 heh, no apply for me, as the target is a macro, not a fn.

dm314:11:01

now you see why you shouldn't write even more macros simple_smile

dominicm14:11:32

I didn't write the original macro, it's actually enlive! I thought I'd have better success than this.

alandipert14:11:33

in macros &form is available

alandipert14:11:43

it gives you the enclosing form, eg {}... so you could do this

alandipert14:11:58

i've never seen it done, maybe it's bad, but it might be awesome

dominicm14:11:05

https://github.com/cgrand/enlive/issues/136 I've opened an issue, hoping someone has something specific to my scenario.

alandipert14:11:11

actually i guess it's not possible because of the even-numbered entries the reader requires

dm314:11:28

but snippet is also a macro..

dominicm14:11:15

The macro hole goes deep

dominicm14:11:26

And way beyond my comprehension.

dominicm14:11:47

But, in general, this is why macros are bad, and you should always provide a form which takes a plain ol' map.

dominicm14:11:34

@dm3 I'm using bouncer, just saw this > Hats off to @dm3 for this pull request.

dominicm15:11:54

I wonder if it's too late for me to just throw out enlive, and use hiccup. Hmm..

majenful15:11:16

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 ?

dominicm15:11:47

@majenful: Use has been deprecated & replaced pretty much.

dominicm15:11:02

Better to use (require '[name.space :refer :all])

dominicm15:11:08

I'm surprised it's still in brave clojure.

majenful15:11:47

I may miss a sentence like « just to illustrate, don’t use it », but in my ebook version he speaks about it

majenful15:11:29

"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."

dominicm15:11:56

Ah, it looks like he's opted to cover everything. But the recommended way to import everything from a namespace is now :refer :all

alexmiller17:11:40

the only time I use use is at the repl when I'm hacking b/c it's shorter

roberto17:11:32

oh, that is one of my pet peeves. Documentation that uses use.

johannjohann19:11:24

hello everybody

johannjohann19:11:45

i got a coworker trying to get clojure up and running and he seems to be bumping into the issue captured in this gist

johannjohann19:11:03

lein repl command hitting a ' java.lang.IllegalArgumentException: array element type mismatch' exception

johannjohann19:11:13

anybody see this before?

markmandel21:11:15

@johangrufman: I'm guessing,, it's some bad syntax somewherre

markmandel21:11:03

Go back to a known stable state - get the repl working, then load the new code into the repl

markmandel21:11:06

that will highlight it

waffletower21:11:26

In a new folder, does "lein new app spork; cd spork; lein repl" also cause a java.lang.IllegalArgumentException?

ffreire21:11:10

Hi @gnejs!

gnejs21:11:29

Anyone "going" to Clojure Remote?