This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-03-10
Channels
- # beginners (356)
- # boot (4)
- # cider (44)
- # cljs-dev (73)
- # cljsrn (19)
- # clojars (5)
- # clojure (57)
- # clojure-brasil (2)
- # clojure-italy (1)
- # clojure-russia (9)
- # clojure-spec (9)
- # clojured (3)
- # clojurescript (15)
- # cursive (19)
- # datomic (10)
- # duct (3)
- # emacs (4)
- # events (1)
- # fulcro (5)
- # immutant (12)
- # keechma (3)
- # lein-figwheel (4)
- # lumo (2)
- # parinfer (11)
- # planck (4)
- # re-frame (3)
- # reagent (5)
- # reitit (1)
- # shadow-cljs (5)
- # spacemacs (6)
has anyone thought about trying to build something like a parser combinator using clojure.spec
— seems like you could (spec/conform *input*)
and get back an AST
i don’t see why specs can’t be recursive which is the only real limitation i could see
@alexstokes have you looked at instaparse?
i had heard of it but had forgotten 😅 @tbaldridge
thanks for the pointer
there was an issue on JIRA where a spec that looked at a string had explosively bad performance
and specs really aren't made for string parsing
i was trying to clojure.spec out a simple RPN calculator and the idea struck me
ah ok
@alexstokes Kern is good, too. I used it in the Advent of Code for a few problems and at least for that it worked very well. https://github.com/blancas/kern
cool — yeah i was mainly curious about using it w/ clojure.spec
i will keep these libs in mind the next time i need one tho
anyone here have any experience using spec
in a (relatively) large application?
i.e. i have this: https://gist.github.com/ralexstokes/990d83e512825d2c87d2355b38e7e16e
and it seems like you would have conform-or-throw
all over the place
so either we turn that into a monadic macro
or there is a different pattern ppl end up using in practice
so curious if anyone has any thoughts/experience with this kind of thing
side note, that looks like it's polish notation, rather than reverse polish notation
oh you are right lol
reverse reverse polish
Would anyone care to explain how does the ((fn
work in this clojure.core function?
https://github.com/clojure/clojure/blob/841fa60b41bc74367fb16ec65d025ea5bde7a617/src/clj/clojure/core.clj#L4814-L4824
how would you suggest to replace the first occurence of an element in an array (or sequence)?
I would initially think about it as an expression containing a function definition, therefore I am not sure I'm aware why this yields a function call to the function definition as per that initial understanding.
they are just creating a named function and executing it immediately, this is done for allowing the recursion in the last line
cljs.user=> ((fn example [& [executed?]] (println "hi!") (when-not executed? (example true))))
hi!
hi!
nil
cljs.user=>
@joelsanchez okay thanks, didn't realize this was valid syntax
@joelsanchez many thanks
oh, by the way, does {:static true}
at the beginning of a function still mean anything in current clojure?
could you remind me the name (as in jargon) for that map at the beginning of a function, so I can look up the reference of it?
it looks like implicit metadata https://clojure.org/reference/metadata
Does calling seq on a map literal maintain the linear order of key-value pairs, as one typed it? When I call it like this, it certainly seems so:
(seq {:a 4 :z 6 :K 1})
=> ([:a 4] [:z 6] [:K 1])
I know there is no strict ordering here, but I’m only interested in the order in which someone types the key value pairs.@mpcarolin in general no, for "small" maps it may happen to. There are sorting ordered mappings in core, and there are insertion ordered mappings available as libraries from the community.
@arrdem Okay thank you — I feared that may be the case. I did some more research on insertion-ordered maps and discovered a native clojure data structure called “array-map”. I might use that. The performance is worse but I only need this for small data sets.
array-map is tricky because if you assoc and it has over N elements you will get an unordered hash-map back
Hmm, perhaps I should step back and ask if there’s a better way to do this. I have a function that will accept pairs of values (where the insert order matters). Something like this:
(foo :a 1 :b 2 :c 3)
And in my function’s body, I would like to work with those values as a sequence of pairs, something like: ([:a 1] [:b 2] [:c 3])
Is there a better way than using seq on array-map? I will only be reading from this data, not adding to it.if you only read, and only read in order (and not doing lookup) just use (partition 2 input)
if you need to use in order and also lookup, don't neglect the fact that you can use (apply hash-map input)
and (partition 2 input)
in the same code
Hi There, has anyone developed an app with pedestal? I am trying to figure out how to start a pedestal server in dev mode… so that I can make-changes and not have to reload the server everytime
@noisesmith That’s exactly what I needed. I’ll just let the function args be [& args] and call (partition 2 args). Thank you
beware that for an odd count of arguments, partition just silently drops the remainder
partition-all will give you a remainder list though
@me1221 The hello world sample has a dev-mode, but in order to see any changes, you have to reload the namespace of whatever you changed. https://github.com/pedestal/pedestal/blob/e9230c3a49b7036b195267c7c24b0c4881c941b5/samples/hello-world/src/hello_world/server.clj#L30