Fork me on GitHub

Hey; is there a :keys destructuring syntax that lets me destructure a bunch of keys with a shared namespace, even if that thing isn’t really a namespace? (I have a bunch of stuff in datascript, a la :widget/color)


I have a lot of :widget/$PROPERTY keys I’m trying to access with as little typing as possible 🙂

Alex Miller (Clojure team)02:09:13

(let [{:widget/keys [color foo bar baz]} …] … )

Alex Miller (Clojure team)02:09:26

assuming you are using 1.9.0-alpha8+


ah; I was playing with that and somehow did ::widget/keys


that makes sense

Alex Miller (Clojure team)02:09:05

::widget/keys will also work, presuming you have a widget alias referring to something


Humdee, having problems with byte-streams library ( when using chunk-size larger than 1MB


bytes.core=> (count (take 10 (bs/convert (bs/to-input-stream (repeat "hello")) (bs/seq-of {:chunk-size (* 1024)})))
bytes.core=> (count (take 10 (bs/convert (bs/to-input-stream (repeat "hello")) (bs/seq-of {:chunk-size (* 1024 1024)})))


wonder why in the last case I don’t get 10 items, but only two 😕


@seancorfield Thank you very much for the detailed explanation. All you said sounds good, also that these essential functions are part of .jdbc now makes me kind of happy. I will try to use .jdbc directly now. In the end, maps and seqs are all we need.


@viesti: here it doesn't just return 2, it returns a different number every time it is run


which is, I think, worse


Now that I realise that @ztellman is here, would you have a clue on why the above behavior (large chunk-size gives less items even when an infinite stream is passed to convert)? 🙂


when reading from a 600MB file instead of a lazy stream, using 5MB chunk-size, I cannot get to end of the file before getting AsynchronousCloseException


@viesti you need to make sure that you're not returning the lazy sequence out of the scope of your enclosing with-open form (if that is what you use)


used doseq on the result


something like (with-open [in...] (doseq [x (bs/convert.... in] ... ))


maybe something in the return value of bs/convert is lazy?


hmm, might be


(with-open [in (io/input-stream "/tmp/bigfile.json")] (doseq [x (bs/convert in (bs/seq-of java.nio.ByteBuffer) {:chunk-size (* 5 1024 1024)})] (println x) (swap! sum inc))) results into AsynchronousCloseException before completing


sum is (def sum (atom 0))


bs/vector-of seems work better, hmm


odd that including byte-streams 0.2.2 in one project, I cannot seem to find bs/vector-of, and on a clean 1.8.0 project, this funtion is available 😕


might be related that there is vector-of in clojure.core


@viesti Are you sure that some other package is not depending on older version of byte-streams and that's what you get? If you run lein deps :tree, you should get a list of conflicts.


does compojure-api offer anything for error handling, like liberator?


@borkdude: what kind of error handling? Exception handling is described here:


@ikitommi thanks, I’ll have a look


is there away to set http-agent before slurp call of url ?


(System/setProperty "http.agent" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.94 Safari/537.36")


(slurp "") CompilerException Server returned HTTP response code: 403 for URL:, compiling:(form-init2601230912767068017.clj:1:10)


but it's working in browser, i know the problem in setting agent, some servers accept specific agents


is there away to fix it?


@ikitommi hi, is there a way how to get api_key directly into swagger using compojure-ui? There used to be a text field on top the swagger js page which is now gone.


@katox New Swagger UI has a button which opens a dialog with text field to set the api key


@katox @juhoteperi does the new ui require the api_key property to be set for the spec? There is an example of that somewhere...


abdullahibra: If you're doing anything more than the simplest of I recommend using clj-http or another http client library. I'm not sure how to do that with slurp, but it's easy with clj-http.


alright, so im struggling with macros again (read the chapter in brave clojure). Just for my own education, i want to write functions, not macros, that manipulate and return code directly. for instance:

(defmacro macropass [macro-function & code]
  (apply macro-function code))

(defn infix [first second third]
  '(second first third))

(macropass infix 1 + 1)


if i do that though, it doesnt work, because

is just a symbol


how do i make it resolve that symbol within the macro?


^whoops, edited to fix name refactor error 😛


@juhoteperi what should I add to spec to the button to appear?


@katox :securityDefinitions {:api_key {:type "apiKey", :name "x-apikey", :in "header"}}


at :swagger :data


@juhoteperi I put it as a sibling to :info under path [:swagger :data] but the index.html is still the same, there is an empty auth_container div. No button anywhere. What should I check?


Anybody have any experience writing macros that might be able to lend a hand?


@katox dont’ put it under :info.


@ikitommi it's only under ':data', it is sibling of ':info'


@katox that example sniplet seems to do the trick. btw, let’s move this to #ring-swagger?


@ikitommi I'll try it and move there, thanks


I just want to throw out my request for help again, in case anyone new is around


is what im trying to do not possible?


I suppose it probably isnt.


thats probably why the concept of a "macro" exists.


@idiomancy A lot of people here are willing to lend a hand, but, what we need is some more information about your problem that you are experiencing and some code, if possible.


@sveri haha, yeah, I had posted that above. I didnt want to be obnoxious and post the same thing again until I got a sign of a pulse


reposting: alright, so im struggling with macros again (read the chapter in brave clojure). Just for my own education, i want to write functions, not macros, that manipulate and return code directly. for instance:

(defmacro macropass [macro-function & code]
  (apply macro-function code))

(defn infix [first second third]
  (list second first third))

(macropass infix 1 + 1)
if i do that though, it doesnt work, because
is just a symbol how do i make it resolve that symbol within the macro?


@idiomancy ah, sorry, I only saw this message: "Anybody have any experience writing macros that might be able to lend a hand?". Otherwise you have to wait I guess.


right, Yeah, I figured I was going to come off as an arse either way.


I usually ask in the clojure forums after a day of no answer here


clojure forums? I've seen the reddit sub


is there a different forum youre referring to?


oh nice! thanks!


@idiomancy You could use resolve in the body of your macro. That's generally not a good idea, because then the macro-function argument to your macro would have different evaluation rules from normal Clojure code. For example, you could not pass an expression that returns a function to macropass. Typically, macros are easiest to understand when they change as little as possible about how code gets evaluated. Most macros only change when the code gets evaluated, not how.


@stuartsierra basically, my big sticking point with macros is that they both manipulate code and evaluate that manipulated code. I want to be able to pass code around and manipulate using normal data structures, and then evaluate it when I'm ready


@idiomancy Then you're not writing macros, you're writing an interpreter. 🙂


ehhhh, I dont know if that was just trolling or what

Jeremie Pelletier14:09:44

@idiomancy you should write the body of your macro like this: `(apply macro-function code)

Jeremie Pelletier14:09:06

without the ` you’re evaluating the code you want to return inside the macro, not the program’s runtime

Jeremie Pelletier14:09:37

you could also remove the apply and use ~@code instead


ahhh, thats right @lambdacoder. its that runtime vs compile time thing


let me try that

Jeremie Pelletier14:09:27

macros run inside the compiler, not your program 🙂


@idiomancy Sorry, not trolling, genuinely trying to help. Macros allow you to execute code at "compile time" which returns code for "runtime." If you're making arbitrary decisions about when things execute, you're already beyond the scope of what macros are designed to do.


A macro has to treat all of its arguments as semi-opaque blobs of code, none of which can be executed until after the macro returns.

Jeremie Pelletier14:09:19

I like to see macros as receiving unevaluated arguments and returning unevaluated code

Jeremie Pelletier14:09:39

which really becomes clear once you implement a toy lisp VM


that does help. rewriting it as

(defmacro macropass [macro-fn & code]
  `(~macro-fn ~@code))
causes it to return the unevaluated form (#object[clojure.core$PLUS 0x837cd4 "clojure.core$PLUS@837cd4"] 1 1) which starts to make the concept more clear


although youd think id just be able to then evaluate that

Jeremie Pelletier14:09:27

oh I just noticed your infix is transforming code as well

Jeremie Pelletier14:09:50

I wonder if that could be done with macrolets?


well, thats the basic idea, I was trying to write functions that manipulate the code, so that I could test them as things that just manipulate and return code without evaluating it


and then put the evaluation part in the macro


thats the concept. its not going well, hahaha

Jeremie Pelletier14:09:00

yeah in that case what stuart said holds, you’ll have to resolve the symbol into a var inside the macro, call it inside the macro and return its result as the macro’s result


which is, of course, not a great idea

Jeremie Pelletier14:09:31

macros call normal functions all the time, but in your case you’re passing in a symbol not a function


and of course theres no way to pass in a function to a macro

Jeremie Pelletier14:09:05

there could be quirks indeed, i’d probably use the fully qualified symbol if the defmacro and infix are in different modules

Jeremie Pelletier14:09:52

no because macros receive unevaluated arguments, so your “infix” is just a symbol at that point - it gets compiled into the infix variable but thats after macro expansion

Jeremie Pelletier14:09:23

resolving will work, its quirky but not that ugly


I basically just want a function that goes "hey, see this stuff im writing? dont evaluate that until I've gotten a chance to play with it and arrange it how I like"

Jeremie Pelletier14:09:05

yeah it will have to resolve its symbol argument into a variable

Jeremie Pelletier14:09:43

basically if you directly call (+ 1 2) in your macro the + is already resolved into #’clojure.core/+ but if + came from the arguments its still the symbol + until passed into (resolve)

Jeremie Pelletier14:09:15

if your macro received the var, it wouldnt be a macro but a normal function 🙂


right. I want a function that takes code and turns into unevaluated symbols, so that I can pass that into a function

Jeremie Pelletier14:09:57

and its only quirky because you’ll get the value of the variable at that point in the compile cycle, if the value changes at runtime the macro will have compiled in the initial value - thats the catch

Jeremie Pelletier14:09:04

in your case you wont rebind infix so its safe


something like

(defn macropass [macro-fn & code]
  (macro-fn ~@code))

(macropass infix (code 1 + 1))


^psuedo, obviously

Jeremie Pelletier14:09:31

(defmacro macropass [f & code] ((resolve f) code)) (defn infix [a o b] (list o a b)) (macropass infix 1 + 2)

Jeremie Pelletier14:09:37

off the top of my head

Jeremie Pelletier14:09:51

oh wait im missing an apply

Jeremie Pelletier14:09:57

(apply (resove f) code)

Jeremie Pelletier14:09:17

or if you want it more readable (-> f resolve (apply code))


right, but because of that whole resolve issue, its kind of a problem, right? Well... or wait, how could that ever be a problem if you use ns qualified symbols? is the danger that someone else re-defs the function name to something else?

Jeremie Pelletier14:09:23

the danger is that if you rebind infix at runtime, your macro will already have run over the initial value


isnt that something one shouldnt do anyway?


rebinding a global name at runtime?

Jeremie Pelletier14:09:57

and im not sure what the context for resolve is: the macro’s ns or the caller’s ns - id pass in qualified symbols just to be sure

Jeremie Pelletier14:09:03

yeah you shouldnt do it

Jeremie Pelletier14:09:07

but its possible 😛

Jeremie Pelletier14:09:23

i usually only rebind vars in development inside my custom user.clj


weird. isnt saying "you shouldnt use resolve because it will break if someone rebinds the name at runtime, which you also shouldnt do" kind of circular? like, if I do follow the guidelines, it wouldnt be a problem, and if I dont follow the guidelines, then it doesnt really matter if theres a guideline for it


lol, i really need to write a lisp and see these things from the ground up at some point

Jeremie Pelletier14:09:37

yeah, i barely if ever need to use resolve

Jeremie Pelletier14:09:52

writing a lisp is a fun weekend project

Jeremie Pelletier14:09:14

and dont do it in clojure, thats cheating 😛


well, ive always wanted a lisp that compiles to python

Jeremie Pelletier14:09:48

you should start with an interpreter first


ive done basic dsl PEG's etc

Jeremie Pelletier14:09:12

that’ll get the data structures down, the reader & printer, evaluation & lexical scopes, etc

Jeremie Pelletier14:09:48

you dont need a PEG to parse a lisp, look at clojure’s

Jeremie Pelletier14:09:18

its basically two dispatch tables on characters and reader macros respectively


anyway, i know ive eaten like an hour of your day, but I wanted to say thanks a lot. I really appreciate your help. I've actually just secured my first professional clojure dev job (I know right, how did they let me in here?) and this kind of support is really awesome. might be keeping the lights on and bread on the table a bit longer!

Jeremie Pelletier14:09:38

nice! glad I could be of some help 🙂


lol. I think I broke clojure. Getting an ExceptionInitializationError from this macro

Jeremie Pelletier16:09:28

I dont think I ever saw this exception hehe

Jeremie Pelletier16:09:46

whats your code like now?


lol, it came from the way I was working with macros. basically, I was trying to eval stuff in a macro a and return eval'd stuff. it was no good.


Honestly, I just moved to a solution where I pass a quoted list of forms into a regular function instead of having a macro at all


so, in other words, something like

(infix '[1 + 1])


the actual function was a bit more sophisticated (it actually builds a memoized version of a function based on the code you give) so I was trying to eval the code as a function and pass it to memoize, then return that memoized function

Jeremie Pelletier17:09:22

oh yeah you can only compile data, not objects

Jeremie Pelletier17:09:41

just like sending stuff on the wire basically


hey all. Is there a way to hook some functionality into when a process will exit?


@nickt (.addShutdownHook (Runtime/getRuntime) (Thread. #(shutdown! system)))


assuming JVM


cool thanks


Hello, a dumb question, Is there any way to (rest {"0814" 0,"0813" 0,}) => {"0813" 0} ?


why do you want that?


You could do (first (rest… but, yeah, I echo @pesterhazy.


for recursive function


like car and cdr from Lisp

smw19:09:12 does that sort of thing pretty well, @fabrao


no, maps aren't sequential


first, second, ffirst, nth, rest, next, etc are basically the car and cdr of Clojure but I think this is an issue of wanting something from a particular data structure that it isn’t designed to meet.


Again, echoing @pesterhazy.


Maps are meant to be accessed by key.


thanks folks I´ll give a try


you can reduce over a map; you'll get k/v pairs


perhaps that fits your use case?


Or you could use keys to get a list of keys and then ping back to the map structure to get values that way.


you can also traverse maps with first / rest, but the latter won't return a map but a sequence; it works by implicitly calling seq on the map


And you can’t guarantee the order in which you’ll get results from that, I’m quite certain.


is there any kind of version of

where an empty collection causes it to resolve as false?


would make my recursive searches a good bit cleaner


You could make one like (defn foo [coll pred] (and (seq coll) (every? pred coll))). Not sure what to call foo tho


yeah, thats what I ended up doing


suppose you start using a library and you realize that you can add enhancements to a part of that library. You make the changes and now you want to test it sufficiently before submitting a Pull Request to the author. Is there a write up on how that is best done? What are the steps (create an uberjar, start a new project, make it a local repo)?? Is there a simpler way?


Thanks @hiredman, I'll read up on that


@aaelony If you’re going to send a PR, many maintainers appreciate you adding tests to the existing suite of tests in the project. And often you can do lein test or lein test-all or some such to make sure your enhancements don’t break their existing tests.


(i.e., it’s nice to include extra tests along with your source file changes, when you send a PR)


@aaelony: It's also nice to open an issue and have a chat about the changes beforehand as well - you can probably ask about their preferences then.


Hopefully the project you’re looking at already has a good suite of tests and documents how to contribute to the project, how to run tests etc.


yup, done that


thanks for all comments


Thanks for caring about tests!


hi! i'm reading through the spec guide; i'm about 1/6 of the way in, so appologies if this question is addressed later in the document :] there seems to be a strong focus on defining "attributes" in the central spec registry by doing eg (s/def :a.namespace/thing int?), and referring to :a.namespace/thing everywhere. it seems like doing (def thing int?) in a-namespace, and referring to a-namespace's thing everywhere, would accomplish the same goal, and so i'm just trying to make sure i understand the purpose of (s/def) and the focus on namespaced keywords. my current theory is that s/def and namespaced keywords are good because you can refer to namespaced keywords without having to actually require the namespace, and so in this way you don't have to worry about circular import errors like i often ran into when using prismatic's schema library. is that the primary reason for this focus on s/def and namespaced keywords, or am i missing a bunch of other obvious upsides?


@jrheard namespaced keywords make good map keys, like regular keywords 🙂


fair point - i had just read the line that introduces s/merge, and so i was looking at eg (s/merge ::foo etc) and thinking "why's this better than (s/merge foo etc)?"; had sort of temporarily forgotten about maps 😄