Fork me on GitHub
#clojure
<
2018-03-10
>
alexstokes00:03:57

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

alexstokes00:03:19

i don’t see why specs can’t be recursive which is the only real limitation i could see

tbaldridge00:03:35

@alexstokes have you looked at instaparse?

alexstokes00:03:36

i had heard of it but had forgotten 😅 @tbaldridge

alexstokes00:03:40

thanks for the pointer

noisesmith00:03:17

there was an issue on JIRA where a spec that looked at a string had explosively bad performance

noisesmith00:03:26

and specs really aren't made for string parsing

alexstokes00:03:28

i was trying to clojure.spec out a simple RPN calculator and the idea struck me

the2bears00:03:49

@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

alexstokes00:03:17

cool — yeah i was mainly curious about using it w/ clojure.spec

alexstokes00:03:37

i will keep these libs in mind the next time i need one tho

alexstokes00:03:39

anyone here have any experience using spec in a (relatively) large application?

alexstokes00:03:17

and it seems like you would have conform-or-throw all over the place

alexstokes00:03:40

so either we turn that into a monadic macro

alexstokes00:03:54

or there is a different pattern ppl end up using in practice

alexstokes00:03:11

so curious if anyone has any thoughts/experience with this kind of thing

noisesmith00:03:19

side note, that looks like it's polish notation, rather than reverse polish notation

alexstokes00:03:42

oh you are right lol

noisesmith00:03:54

reverse reverse polish

the2bears00:03:13

recurse polish notation

blackawa07:03:37

Can I use delimiter to int literal in clojure like ruby can(`n = 100_000`)?

matan10:03:14

And why that form of recursion is used instead of loop recur ?

roti10:03:21

how would you suggest to replace the first occurence of an element in an array (or sequence)?

roti10:03:19

map and for do the job, but traverse the whole array/sequence

roti10:03:09

recur would be a solution, but I wonder if I could do it using seq library functions

matan10:03:22

I think what initially eludes me is why would (( be a valid expression

matan10:03:27

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.

matan10:03:36

I must be missing something basic and obvious about it

joelsanchez11:03:17

they are just creating a named function and executing it immediately, this is done for allowing the recursion in the last line

joelsanchez11:03:38

cljs.user=> ((fn example [& [executed?]] (println "hi!") (when-not executed? (example true))))
hi!
hi!
nil
cljs.user=>

matan11:03:40

@joelsanchez okay thanks, didn't realize this was valid syntax

matan11:03:11

oh, by the way, does {:static true} at the beginning of a function still mean anything in current clojure?

matan11:03:00

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?

bronsa13:03:51

@matan no :static is useless

matan14:03:32

I wonder why it's there in the clojure code ....

mpcarolin22:03:06

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.

arrdem22:03:12

@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.

mpcarolin22:03:18

@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.

noisesmith22:03:29

array-map is tricky because if you assoc and it has over N elements you will get an unordered hash-map back

mpcarolin22:03:35

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.

noisesmith22:03:08

if you only read, and only read in order (and not doing lookup) just use (partition 2 input)

noisesmith22:03:26

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

geeky_vin22:03:38

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

mpcarolin22:03:48

@noisesmith That’s exactly what I needed. I’ll just let the function args be [& args] and call (partition 2 args). Thank you

noisesmith22:03:29

beware that for an odd count of arguments, partition just silently drops the remainder

noisesmith22:03:38

partition-all will give you a remainder list though

onionpancakes22:03:44

@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