Fork me on GitHub
#clojure
<
2018-12-23
>
ahungry01:12:45

Hah the description on that was identical to what you were looking for

jaide04:12:41

(remove empty? '(() (println "hello") 2)))
Results in an error.
Don't know how to create ISeq from: java.lang.Long
Should it?

haus04:12:06

the docs for empty? say that it only works on collections, so an error makes sense to me

seancorfield06:12:52

@jayzawrotny You probably want (remove (comp empty? seq) '(() (println "hello") 2)) ?

seancorfield06:12:31

Er, no, not quite..

seancorfield06:12:24

Maybe this

user=> (remove #(and (sequential? %) (empty? %)) '(() (println "hello") 2))
((println "hello") 2)
user=>                                                                                                                  

jaide07:12:44

Thanks, that is what I was thinking. It was an unexpected behavior that took a while for me to find so I was curious how others felt about it.

vlad_poh15:12:20

Howdy. newbie question here. I'm playing with azure bots and i need to respond to the bot in 15 seconds or less regardless of how long it takes me to process. (15 seconds is not configurable) I've tried futures but they didn't fire all the time. I tried agents but it seems to wait for everything to be done. What can i do or try?

didibus16:12:57

You can also try tea-time https://github.com/aphyr/tea-time/blob/master/README.md if you don't want to do interrop

schmidt7319:12:49

Hey I'm trying to write a macro that converts something of the form [:or f1 f2 [:and f3 f4]] -> (or-perm f1 f2 (and-perm f3 f4)). It works as expected on inputs of the form (:or f1 f2) and [:or f1 f2], but not on inputs such as '(:or f1 f2) in the latter case it outputs '(or-perm f1 f2) instead of the desired (or-perm f1 f2). I'm having trouble understanding why.

schmidt7319:12:26

The macro looks like ^

seancorfield19:12:35

@henri.schmidt '(..) is shorthand for (quote (..)) and that's what the macro receives.

seancorfield19:12:05

So it's as if you passed in ['quote [..]]

schmidt7321:12:08

Why does the second throw an error when the first runs fine?

schmidt7321:12:24

Just calling the function isSchmidt73? normally works.

seancorfield22:12:25

That will create lists with the values of isAuthenticated? and isSchmidt73? and then eval will call those values as functions.

seancorfield22:12:25

What is the value that isSchmidt73? evaluates too? i.e., what is returned from perm/from-claims?

schmidt7322:12:57

It should return a function

schmidt7322:12:29

The function is simply a predicate over a map.

schmidt7322:12:40

Same as isAuthenticated?

seancorfield22:12:07

So ((perm/from-claims {:user "schmidt73"}) {}) is what you're evaluating here.

seancorfield22:12:30

And that fails as-is? (ignore the eval/`list` stuff for now)

schmidt7322:12:02

No that returns false as expected.

schmidt7322:12:33

Which maybe its a symbol lookup namespacing error, but I'm very new to clojure so I have no idea.

schmidt7322:12:00

I read something about how eval on closures is bad.

seancorfield22:12:24

You should almost never need eval...

schmidt7322:12:08

Yeah it was in the context of figuring out some macro errors.

schmidt7322:12:14

I'm new to macros and they are a bit confusing to me.

seancorfield22:12:48

The first rule of macro club is... don't use macros 🙂

💯 4
schmidt7322:12:49

I wrote a macro so I could write routes such as the following:

seancorfield22:12:12

Try to do everything with plain functions. Macros really are only for 1) syntactic sugar (on top of functions) and 2) for constructs where you don't want the semantic of function evaluation (i.e., you don't want arguments evaluated).

schmidt7322:12:23

Yeah 2) they are necessary

schmidt7322:12:30

1) is this case

schmidt7322:12:38

It was just a lot to write (def perms (perm/or isSchmidit73 isOliveBoi)) and then (wrap-handler perms handler) around all my handlers that need authentication

seancorfield22:12:52

I think your problem is that your eval above is working with the values of those symbols instead of the symbols themselves

seancorfield22:12:08

(eval (list 'isSchmidt73 {})) -- does that work?

schmidt7322:12:34

Yup 🙂

schmidt7322:12:49

And why is that?

schmidt7322:12:40

Why is there that difference still between the two?

victorb22:12:56

I guess this would be helpful reading: https://www.braveclojure.com/read-and-eval/

seancorfield22:12:46

Consider this:

(def foo 42)
(eval (list 'foo {})) ;=> (eval '(foo {}))
(eval (list foo {})) ;=> (eval '(42 {}))
does that help explain it?

schmidt7322:12:54

Yes, I understand that part.

schmidt7322:12:24

But here we have (eval '(isAuth? {})) giving a result and (eval '(isSchmidt? {})) giving an error

schmidt7322:12:29

I would figure they would both fail.

seancorfield22:12:05

You said this (eval (list 'isSchmidt73? {})) worked, yes?

seancorfield22:12:34

That's the same as (eval '(isSchmidt73? {}))

seancorfield22:12:42

What will not work is (eval (list isSchmidt73? {}))

schmidt7322:12:59

Yeah but why does (eval (list isAuth? {})) work then?

schmidt7322:12:31

Is it because isAuth? is defined in same file?

schmidt7322:12:44

isAuth? doesn't use a closure either.

schmidt7322:12:25

Also, thank you so much for all of your help. I'm doing a better job understanding this stuff now.

hueyp22:12:57

is there a way to make a top level var within a macro expansion that works with AOT? I don’t even know if I’m using all these words right … but like this: https://gist.github.com/eyston/21a7b05cfaf1fbee886a205941e2d3bd

hueyp22:12:04

this makes the var but its unbound when AOT … which makes sense, but I’m wondering if I can abuse something to make it have the value 😜

hueyp22:12:11

hm the gist didn’t expand, its

(defmacro macro-def
  [k v]
  (intern *ns* k v))

(when false
  (macro-def foo "bar"))

(defn -main
  []
  (println foo))

seancorfield22:12:22

@henri.schmidt Hard to say without seeing the source of from-claims I suspect...

seancorfield23:12:49

@hueyp I think the issue is the way *ns* is evaluated in different contexts. Add the following above the defmacro: (def my-ns *ns*) and then change the intern call to use my-ns instead.