This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-09-15
Channels
- # aws-lambda (3)
- # beginners (37)
- # boot (294)
- # carry (1)
- # cider (38)
- # cljs-dev (37)
- # cljsjs (88)
- # clojure (187)
- # clojure-android (2)
- # clojure-austin (1)
- # clojure-dusseldorf (9)
- # clojure-hk (3)
- # clojure-italy (12)
- # clojure-russia (36)
- # clojure-spec (55)
- # clojure-uk (27)
- # clojurescript (75)
- # community-development (5)
- # conf-proposals (2)
- # copenhagen-clojurians (3)
- # cursive (9)
- # datomic (54)
- # devcards (5)
- # devops (3)
- # dirac (69)
- # emacs (6)
- # ethereum (1)
- # euroclojure (1)
- # events (3)
- # funcool (1)
- # hoplon (20)
- # immutant (4)
- # luminus (14)
- # midje (4)
- # om (178)
- # om-next (2)
- # onyx (47)
- # pedestal (19)
- # protorepl (20)
- # re-frame (14)
- # reagent (54)
- # ring (2)
- # ring-swagger (7)
- # test-check (10)
- # uncomplicate (11)
- # untangled (9)
- # yada (9)
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 🙂
(let [{:widget/keys [color foo bar baz]} …] … )
assuming you are using 1.9.0-alpha8+
::widget/keys will also work, presuming you have a widget alias referring to something
which you don’t :)
Humdee, having problems with byte-streams library (https://github.com/ztellman/byte-streams) when using chunk-size larger than 1MB
bytes.core=> (count (take 10 (bs/convert (bs/to-input-stream (repeat "hello")) (bs/seq-of java.io.InputStream) {:chunk-size (* 1024)})))
10
bytes.core=> (count (take 10 (bs/convert (bs/to-input-stream (repeat "hello")) (bs/seq-of java.io.InputStream) {:chunk-size (* 1024 1024)})))
2
@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
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)
(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
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 😕
@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.
@borkdude: what kind of error handling? Exception handling is described here: https://github.com/metosin/compojure-api/wiki/Exception-handling
Hi guys
is there away to set http-agent before slurp call of url ?
i tried this:
(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 "http://www.demilked.com/magazine/wp-content/uploads/2015/11/new-hybrid-animals-photoshop-37.jpg") CompilerException java.io.IOException: Server returned HTTP response code: 403 for URL: http://www.demilked.com/magazine/wp-content/uploads/2015/11/new-hybrid-animals-photoshop-37.jpg, 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)
@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?
@katox that example sniplet seems to do the trick. btw, let’s move this to #ring-swagger?
@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
macro-function
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.
@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. 🙂
@idiomancy you should write the body of your macro like this: `(apply macro-function code)
without the ` you’re evaluating the code you want to return inside the macro, not the program’s runtime
you could also remove the apply and use ~@code instead
ahhh, thats right @lambdacoder. its that runtime vs compile time thing
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.
I like to see macros as receiving unevaluated arguments and returning unevaluated code
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 clearoh I just noticed your infix is transforming code as well
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
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
macros call normal functions all the time, but in your case you’re passing in a symbol not a function
there could be quirks indeed, i’d probably use the fully qualified symbol if the defmacro and infix are in different modules
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
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"
yeah it will have to resolve its symbol argument into a variable
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)
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
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
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))
(defmacro macropass [f & code] ((resolve f) code)) (defn infix [a o b] (list o a b)) (macropass infix 1 + 2)
off the top of my head
oh wait im missing an apply
(apply (resove f) code)
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?
the danger is that if you rebind infix at runtime, your macro will already have run over the initial value
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
yeah you shouldnt do it
but its possible 😛
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
yeah, i barely if ever need to use resolve
writing a lisp is a fun weekend project
and dont do it in clojure, thats cheating 😛
you should start with an interpreter first
that’ll get the data structures down, the reader & printer, evaluation & lexical scopes, etc
you dont need a PEG to parse a lisp, look at clojure’s clojure.lang.LispReader.java
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!
nice! glad I could be of some help 🙂
lol. I think I broke clojure. Getting an ExceptionInitializationError from this macro
I dont think I ever saw this exception hehe
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
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
oh yeah you can only compile data, not objects
just like sending stuff on the wire basically
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.
https://github.com/nathanmarz/specter 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.
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
every?
where an empty collection causes it to resolve as false?You could make one like (defn foo [coll pred] (and (seq coll) (every? pred coll)))
. Not sure what to call foo
tho
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?
https://github.com/technomancy/leiningen/blob/master/doc/TUTORIAL.md#checkout-dependencies
@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)
very true, @seancorfield
@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.
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?