Fork me on GitHub
#clojure
<
2018-10-28
>
darwin15:10:04

Hi, maybe I’m reinventing the wheel here, but I wanted to bounce an idea in this channel. I wrote a simple sugary macro for code trying to do state monads. It looks good so far on some toy examples. Just wanted to ask if you think it is a bad idea and what potential drawbacks I could introduce by using this heavily. Or maybe you know some library or code which does a similar thing and is already battle tested. https://gist.github.com/darwin/883b9fd2b9012d79d4bbb14a641d36ab, for context: inspired by @tbaldridge’s post here https://www.reddit.com/r/Clojure/comments/8pyxk8/motivation_for_monads/e0gb6on, please respond in a threaded conversation, thanks.

nooga16:10:40

hey, does anyone remember this talk in which, the speaker was coding live, showing off how easy it is to consume an http api and do something cool with the data using Clojure?

Shantanu Kumar16:10:06

Should this be allowed? (let [new 45] new) Because new is a special form.

narendraj916:10:52

(let [new (fn [] 10)] (new Exception)) For this thing, Clojure becomes a Lisp-2. 😄

narendraj916:10:28

(let [new 10] (new Exception) (println new))

💯 4
👍 4
rich 12
billyr17:10:21

Any tools out there to help navigate large clojure projects? I mean like a rough outline of defined vars in a tree format, preferably using static analysis

nooga17:10:56

thanks! but that’s not it 😞

zilti21:10:30

Is such a weird difference in behaviour of nested macros vs. macro + eval normal? https://gist.github.com/zilti/f008287e05cefda634710361eea8860d

hiredman21:10:05

that isn't a nested macro

hiredman21:10:39

` doesn't mean "macro" it means quote

hiredman21:10:04

it is kind of a special quote that is useful for writing macros, but it isn't a macro

zilti21:10:11

Yes, nested quotes is what I mean, sorry.

hiredman21:10:45

so what you are doing is getting confused as to the levels of quoting you are doing

hiredman21:10:07

your let likely is something that should be done at macro expand time (shouldn't be part of the macro expansion)

hiredman21:10:10

hrrm, I am not sure, it looks kind of like you are trying to mix things that happen at macroexpand time with information that isn't known until runtime, which will never work

zilti21:10:16

I need the argument instance to get resolved, and the only way this seems to be possible is when it's part of the expansion

hiredman21:10:03

but you are trying to generate code based on what it resolves to

zilti21:10:08

The problem this macro has (the one at the bottom) is that it screws up creating the proxy macro. I get an error about cons not being able to get cast into what it wants

zilti21:10:30

Yes, hence the nested quotes, for what I understood how nested quotes work

hiredman21:10:31

instance has a value at runtime, at macro expand time it is just a symbol

zilti21:10:19

So what are nested quotes for then?

hiredman21:10:04

sometimes you are doing something really complicated, but it is really rare, the most common case is macros that expand in to macro definitions

hiredman21:10:52

usually if something looks like a nested quote, it is really a quotation with another quotation spliced in at the same level of quoting

hiredman21:10:28

the nested quoting in your connect function means you get something like (.setSomeMethodName instance '(proxy ...))

hiredman21:10:49

so you are passing the quoted literally proxy form to the setmethod being called

hiredman21:10:23

also it is generally better to use the desugared dot form in macros

hiredman21:10:40

(. instance (setSomeMethodName ..))

zilti21:10:49

So the only "solution" in my case is the use of eval?

hiredman21:10:41

because you want to generate code as a result of a value known only at runtime

hiredman21:10:17

I would suggest instead of using eval taking and step back and looking at what you are trying to do and finding a different strategy

hiredman21:10:42

like, maybe functional param is a small known set of types, and you can just upfront generate a proxy for each

zilti22:10:04

No, that's unfortunately not possible, because it's to interface with Java's functional interfaces, and there's potentially infinitely many of them