This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-12-08
Channels
- # adventofcode (31)
- # beginners (97)
- # bigdata (2)
- # boot (276)
- # cider (17)
- # cljsrn (5)
- # clojure (150)
- # clojure-china (3)
- # clojure-conj (8)
- # clojure-greece (1)
- # clojure-india (1)
- # clojure-korea (1)
- # clojure-new-zealand (4)
- # clojure-russia (40)
- # clojure-spec (119)
- # clojure-uk (116)
- # clojurescript (87)
- # code-reviews (110)
- # core-async (4)
- # cursive (11)
- # datomic (26)
- # garden (4)
- # gorilla (7)
- # hoplon (82)
- # humor (1)
- # jobs (2)
- # jobs-discuss (10)
- # luminus (17)
- # onyx (60)
- # planck (2)
- # play-clj (2)
- # protorepl (70)
- # re-frame (121)
- # reagent (7)
- # ring-swagger (3)
- # rum (16)
- # test-check (16)
- # untangled (12)
- # yada (20)
Is there going to be a state of clojure survey this year?
Does anyone know any good resources to start learning grammars? I'm thinking super basic, with the goal of building the grounding to eventually understand things like instaparse at the theory level.
Hello Clojurians, does command line api has some “reserved” args? I’ve defined -m in cli args, but for example
lein run -m 11
> Option -m requires a valid namespace argument, not 11.
but if I change -m to -x in core.clj and then run:
lein run -x 11
it works…
I’m confused… :D
@shaun-mahood you might have to just try to find @puzzler's amazon reading list
@chokheli that's leiningen specific thing. -m tells lein that you want to call a main function in a specific namespace
in school we had to read the algol 60 (68?) paper specification, which included for the first time a BNF grammar
By the way, I have another question - how can I interrupt the execution of function on “Exception”?
@chokheli ok I see what you're saying, if you add another dash like lein run --m 11
lein will ignore it, but then again your shell might as well
@chokheli if you run that snippet at the repl you'll see that the exception stops the execution
when you run this at the repl (let [a (slurp "nofile.txt") b (do (Thread/sleep 10000) a)] (println b))
does it take ten seconds before you get an error or instantly?
@chokheli but either way, using try/catch will let you handle exceptions gracefully https://clojuredocs.org/clojure.core/try
although I still think letting an uncaught exception bubble up will give you the desired behavior. (let [a (try (slurp "nofile.txt") (catch Exception e (str "caught exception: " (.getMessage e)))) b a] (println b))
in this code snippet the exception message gets stored in the let binding "a" and the let binding "b" gets the value of "a" then the body prints b which is the exception message
@chokheli You can say lein run -- -m 11
and then -m 11
will be passed to your -main
function. The --
argument says the rest of the arguments are literal and passed to the program.
has anyone used garden.css
here, before?
@biscuitpants hello~ there's always #css if you need something
@biscuitpants extensively, yes
oh sweet @acron
i just need help with something. we memoize
our loader svg, using garden.css
. it works perfectly fine in a jar, produced by lein
. but, when running a repl, i get Cannot create ISeq from Keyword
, and it goes into the garden namespaces. if i just eval
that file, then the error goes away. just interested as to why this happens?
i’m assuming its something to do with how memoize caches
@biscuitpants got any code you can show me? I've never thought to memoize
anything fed into garden
yeah sure
Curious. I don't know enough about memoize
to give you any advice regarding your specific error. All I can say is that given experience using garden
we've moved all our CSS processing to a build step using https://github.com/noprompt/lein-garden as this gives you an array of benefits.
@acron thanks, i can take a look at that. that’s quite a clever idea
@biscuitpants It would work around your issue; I said 'extensively'...yet I've never tried to memoize
so sorry 🙃
hahah, no worries!
🦆 right?
i mean its a non-issue, since it works in our jar. i’m just curious as to why i have to almost ‘force’ evaluate that namespace
Hello all, is there any way to see a non-referenced or non-used functions in lein project?
@fabrao https://github.com/jonase/eastwood should help you
its a lein plugin that is a linting tool
Is there a way to get the fully qualified name of a function from a function var? Maybe I should say the original function name from defn.
@yonatanel backtick:
`foo
@rauh It doesn't preserve the original name, if for example you (def x my-original-fn) and then do `x
I see there's a demunge function which takes a class name, but I need it in clojurescript as well so now trying to figure out how to get the munged name in cljs.
@yonatanel what are you trying to do ?
@mccraigmccraig I need to reference an existing function, using a fully qualified keyword. That's how the Onyx api works and of course I could just hard-code the keyword because I know the function name, but in clojurescript if you forget to require the namespace containing the function, the function will not exist in runtime.
@yonatanel i haven't used onyx in cljs - presumably it doesn't work with advanced compilation ?
but surely you need to require the namespaces with your fns from your catalog or lifecycle namespaces anyway, so hard-coded keywords should be fine
@mccraigmccraig You just need to require the stuff you reference, and define that stuff with ^:export
@mccraigmccraig Since you supply Onyx with keywords, they could be anything and you can forget to require
@danielcompton: yes, we are working on state of Clojure survey. I started bugging people about it Oct 1st. Apparently I need to start even earlier. :)
I'm working on recreating the shogi board game in clojure. Now a pawn can promote to another piece. In the pawn datastructure i've got {:promotes 'super-pawn} which is the name of the relevant data structure. When a pawn promotes i redefine it by (def pawn (eval pawn :promotes)). Is this a good use for eval? Or is there a better way to achieve the functionality?
@alexmiller Sorry to trouble you, but does there happen to be a spec in Clojure for checking if a data structure is valid destructuring syntax?
@alexmiller Ah, excellent. Do you happen to know where it is or what it’s called?
See the clojure.core.specs namespace
Oh! I didn’t think to look in the core directory.
::binding and ::bindings in there
Perfect, thanks a lot
And you can see how it's used in the let, defn, etc spec
@wilcov: I would recommend trying to avoid eval in such a case, though there are tradeoffs. Would you be willing to store the function super-pawn instead of the symbol than names it? That is, {:promotes super-pawn} rather than {:promotes 'super-pawn}?
@chouser i'm not against storing the function. But since shogi has 40 pieces, most of which can promote, i was looking at storing the symbol and using the eval function as a way for halving the size of the data structure. Admittedly i've not run any benchmarks so i'm not sure if such a "optimization" is even necessary. Could you explain why you would recommend against avoiding eval?
@wilcov Mainly eval is a big hammer, can do a lot of things you probably don't need it to in that case, which makes it harder for people to understand later what that line of code does. It's also relatively slow, bringing in the Clojure compiler, making your code less compatible with Clojurescript, etc. These are the general arguments against using eval, unless of course it actually need its power.
@wilcov I don't understand the data structure size argument. When you "store" a function in a map, you're really just storing a reference -- there's generally still just a single copy of the function itself in memory. But maybe I'm misunderstanding your point.
@chouser it could very well be that i've simply misunderstood how the function is being evaluated (or when). I'll add a code snippet in which i'll try to explain my thought process
@gdeer81 I thought the environ plugin would take care that the secret key is avaible on heroku
@roelofw it makes sure that you can pull an existing env variable into your app, but you wouldn't use it the other way because at that point you're hard coding secret keys into your codebase which is what you were trying to avoid
@roelofw what you want to do is go to your account in heroku, find your app, go to configuration, and set the key value pair for your secret key. Then use environ to pull that key in by name
now i hope someone will give a review. I already asked in the code-reviews channel but till now no luck
is there a function that takes a fn and a sequence and returns a sequence of two sequences with things where the fn was truthy and falsy respectively?
I seem to recall something...
maybe I'm thinking of partition-by, but that wouldn't do exactly what I want because the items are not sorted
group-by is close enough
@jcromartie can you give a example of the input and output that you want ?
(foo even? [1 2 3 4]) => [[2 4] [1 3]]
I know it's easy to write, I'm just wondering if there's an idiomatic way built in
right
I don't think it exists in clojure.core which is fine
I can also do (let [xs (filter x? coll) non-xs (remove (set xs) coll)] ...)
which is clear enough
yeah, I was thinking group-by is close enough, too, but it doesn't read well
anyway
not a big deal
hah perfect
brilliant, even!
I found it here : http://blog.jayfields.com/2011/08/clojure-partition-by-split-with-group.html
:thumbsup:
for those not on twitter, i posted my clojure/conj sketchnotes to my blog: http://tankthinks.net/posts/2016-12-06-clojure-conj-sketchnotes.html
also, i've been giving a presentation at work to colleagues new to clojure, i posted that presentation: http://tankthinks.net/posts/2016-12-07-introduction-to-clojure.html
it's probably not the same w/out my dulcet voiceover
How to go from [{:key 1 :val 1} {:key 2 :val 2}] => {1 {:key 1 :val 1} 2 {:key 2 :val 2}}
(into {} (map (juxt :key identity)) ...)
@roelofw @jcromartie: Call me pedantic but I can’t deal with the last solution running through the sequence twice, calling the predicate function twice. I’d probably do something like this:
(defn partition-by' [f coll]
(->> (group-by f coll) (sort-by first) (map second)))
(partition-by' even? (range 4))
;; => ([1 3] [0 2])
(i’ve seen winnow
used as a name for this type of function before, so that’s what i usually call it; probably not an accepted standard name though)
Hey guys! Just wanted to say hi! I'm just starting off learning clojure and clojurescript and it looks really exciting 🙂
I just have a question for all of you, though: I'm interested in learning both Clojure and Clojurescript, but probably Clojurescript first as it would be more applicable to what I do day to day.
Do you think the Clojure resources, like the for the Brave and True book would also teach me Clojurescript?
I know there are some differences between the languages so I want to get that straight before I dive too deep into Clojure.
if you want to do algorithm type stuff, there will be very little difference, but once you start looking at build tooling (packaging etc), host interop, custom data structures, they diverge pretty fast
I think the development experience on the clojure side is better, so that would be what I would steer people starting out towards, but I bet people who spend their time writing clojurescript feel differently
Hey @spasov! I’ll second what @hiredman said. I think it’s a touch easier to get started on the Clojure side of things. But I still think that book would be decent place to get started if you want to learn Clojurescript. They’re pretty similar until you get past the basics. You might ask #clojurescript for a second opinion.
@spasov as far as books go, there is an excellent book by Luke VanderHart and Stuart Sierra called "ClojureScript: Up and Running" I think it is geared toward people coming from a Javascript background, meaning that it doesn't assume you already know Clojure so it goes over enough syntax and concepts to get you going
does someone know of good blog or project that create parse trees in clojure which parses into code in some different language doing something like clojure.core.match and variants. On that topic as parser beginner, would clojure.spec come in handy for parsing outside of testing?
@spasov: https://github.com/magomimmo/modern-cljs is a good resource for ClojureScript as well
https://github.com/hiredman/prubasic is a toy compiler that uses instaparse
yes, I've been doing that for a while. But I've come to a conclusion that I want to use native clojure functions but not my own language. I prefer to extend-types to create my own parse-tree that use bison-ish rules to make them. But from the tree to code is where Im looking for right solutions.
"I prefer to extend-types to create my own parse-tree that use bison-ish rules to make them."
if you are dealing with defrecords and deftypes and a tree in memory already, then you are already parsed
yes I may be looking for evaluator. So I ask for understanding for the lack of my academical knowledge in computer science 🙂
so tree rewriting is going to be a function from input tree to output tree, usually a recursive function
I want to share many clojure functions and use my own, and create rules. Just given that I have the knowledge to create some tree that I could recur over. Looked at the parsing solution offerd here http://troydm.github.io/blog/2016/04/11/writing-parser-combinator-library-in-clojure/ I feel its in the right direction but still mini implementation of instaparse still in a way.
I would look at something like http://lisperator.net/pltut/, and just skip the parsing prelude
nice, I need the basic knowledge, one step at a time. So thanks for the resources, bit hard to find in this area. But plenty exist in Haskell.
I just wrote a blogpost about using clojure.spec for parsing, for usage with the advent of code: http://thegeez.net/2016/12/09/parsing_clojure_spec_advent_of_code.html
@thegeez you might enjoy using the klipse plugin for interactive code snippets in blog posts, eg http://blog.jrheard.com/procedural-dungeon-generation-drunkards-walk-in-clojurescript