Fork me on GitHub
#clojure
<
2016-12-08
>
danielcompton00:12:13

Is there going to be a state of clojure survey this year?

shaun-mahood02:12:20

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.

agigao04:12:14

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

gdeer8104:12:18

@shaun-mahood you might have to just try to find @puzzler's amazon reading list

gdeer8104:12:15

@chokheli that's leiningen specific thing. -m tells lein that you want to call a main function in a specific namespace

dpsutton04:12:35

in school we had to read the algol 60 (68?) paper specification, which included for the first time a BNF grammar

gdeer8104:12:48

-x doesn't mean anything so lein ignores it an just runs the default main function

agigao04:12:41

yeah, I comprehend that but is there any workaround? :)

agigao04:12:36

By the way, I have another question - how can I interrupt the execution of function on “Exception”?

gdeer8105:12:57

@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

gdeer8105:12:47

@chokheli if you run that snippet at the repl you'll see that the exception stops the execution

agigao05:12:46

it stops, but only when b tries to access to a non-existent data

gdeer8105:12:13

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?

gdeer8105:12:55

@chokheli but either way, using try/catch will let you handle exceptions gracefully https://clojuredocs.org/clojure.core/try

gdeer8105:12:21

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

agigao05:12:39

Thank you! :)

seancorfield07:12:11

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

biscuitpants08:12:04

has anyone used garden.css here, before?

akiroz09:12:13

@biscuitpants hello~ there's always #css if you need something

biscuitpants09:12:31

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?

biscuitpants09:12:38

i’m assuming its something to do with how memoize caches

acron09:12:18

@biscuitpants got any code you can show me? I've never thought to memoize anything fed into garden

acron09:12:34

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.

biscuitpants09:12:22

@acron thanks, i can take a look at that. that’s quite a clever idea

acron09:12:58

@biscuitpants It would work around your issue; I said 'extensively'...yet I've never tried to memoize so sorry 🙃

biscuitpants09:12:14

hahah, no worries!

biscuitpants09:12:36

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

fabrao09:12:12

Hello all, is there any way to see a non-referenced or non-used functions in lein project?

biscuitpants09:12:45

its a lein plugin that is a linting tool

yonatanel10:12:48

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.

rauh10:12:17

@yonatanel backtick:

`foo

yonatanel10:12:57

@rauh It doesn't preserve the original name, if for example you (def x my-original-fn) and then do `x

yonatanel10:12:56

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.

mccraigmccraig10:12:30

@yonatanel what are you trying to do ?

yonatanel10:12:27

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

yonatanel10:12:47

basically I need (fn->kw some/fn) => :some/fn

rauh11:12:50

You can just do (.-name fn-obj) in javascript, though I'm not sure that's a good idea.

yonatanel11:12:07

@rauh not too bad either

mccraigmccraig11:12:07

@yonatanel i haven't used onyx in cljs - presumably it doesn't work with advanced compilation ?

mccraigmccraig11:12:08

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

yonatanel11:12:10

@mccraigmccraig You just need to require the stuff you reference, and define that stuff with ^:export

yonatanel11:12:09

@mccraigmccraig Since you supply Onyx with keywords, they could be anything and you can forget to require

Alex Miller (Clojure team)13:12:46

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

wilcov14:12:34

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?

weavejester14:12:15

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

weavejester14:12:59

@alexmiller Ah, excellent. Do you happen to know where it is or what it’s called?

Alex Miller (Clojure team)14:12:03

See the clojure.core.specs namespace

weavejester14:12:23

Oh! I didn’t think to look in the core directory.

Alex Miller (Clojure team)14:12:28

::binding and ::bindings in there

weavejester14:12:48

Perfect, thanks a lot

Alex Miller (Clojure team)14:12:03

And you can see how it's used in the let, defn, etc spec

roelofw14:12:43

Someone who can help me to make a deploy on heroku working

roelofw14:12:19

I have a secret key in profiles.clj

roelofw14:12:50

To make it work with git I deleted the profiles.clj in .gitignore

roelofw14:12:01

Then I make a git add .

roelofw14:12:07

git commit

roelofw14:12:20

and a git push heroku

roelofw14:12:48

but when I look into the heroku logs , the secret key is still not found

roelofw14:12:59

What can I do next to make it work

chouser15:12:10

@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}?

wilcov15:12:49

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

wilcov15:12:21

*against using eval

gdeer8115:12:40

@roelofw you usually put environmental variables in heroku through their ui

roelofw15:12:33

@gdeer81 then I have to find out how to do that

chouser15:12:25

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

chouser15:12:11

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

wilcov15:12:44

@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

wilcov15:12:24

Ofcourse if it's still a reference 'behind the scenes' then my argument is null

roelofw15:12:47

@gdeer81 I thought the environ plugin would take care that the secret key is avaible on heroku

gdeer8115:12:04

@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

gdeer8115:12:18

@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

roelofw15:12:08

@gdeer : thanks, finanly I got my app working.

roelofw15:12:48

now i hope someone will give a review. I already asked in the code-reviews channel but till now no luck

jcromartie16:12:35

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?

jcromartie16:12:51

I seem to recall something...

jcromartie16:12:52

maybe I'm thinking of partition-by, but that wouldn't do exactly what I want because the items are not sorted

jcromartie16:12:58

group-by is close enough

roelofw16:12:42

@jcromartie can you give a example of the input and output that you want ?

jcromartie16:12:19

(foo even? [1 2 3 4]) => [[2 4] [1 3]]

jcromartie16:12:05

I know it's easy to write, I'm just wondering if there's an idiomatic way built in

roelofw16:12:58

hmm, that is not what we wanted

jcromartie16:12:14

I don't think it exists in clojure.core which is fine

jcromartie16:12:47

I can also do (let [xs (filter x? coll) non-xs (remove (set xs) coll)] ...)

jcromartie16:12:16

which is clear enough

roelofw16:12:21

maybe this one :

roelofw16:12:36

:clj (group-by even? [1 2 4 3 5 6])

jcromartie16:12:22

yeah, I was thinking group-by is close enough, too, but it doesn't read well

jcromartie16:12:35

not a big deal

roelofw16:12:07

or this one

jcromartie16:12:55

brilliant, even!

tankthinks16:12:02

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

tankthinks16:12:28

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

tankthinks16:12:44

it's probably not the same w/out my dulcet voiceover

borkdude18:12:23

How to go from [{:key 1 :val 1} {:key 2 :val 2}] => {1 {:key 1 :val 1} 2 {:key 2 :val 2}}

borkdude18:12:39

I have:

(fn [coll]
                 (reduce
                  (fn [m {:keys [key] :as e}]
                    (assoc m key e))
                  {}
                  coll))

borkdude18:12:46

but maybe I’m missing some core function here

gfredericks18:12:11

(into {} (map (juxt :key identity)) ...)

borkdude18:12:39

awesome, thanks

camdez18:12:13

@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])

jrheard19:12:18

(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)

bradford19:12:11

What's up with #cursive? The latest version I have was built a year ago in 2015

cfleming19:12:44

@bradford There have definitely been many releases since then.

cfleming19:12:54

Probably better to take this over to #cursive.

camdez19:12:06

@jrheard: Interesting. I love having a name for it.

spasov21:12:16

Hey guys! Just wanted to say hi! I'm just starting off learning clojure and clojurescript and it looks really exciting 🙂

spasov21:12:56

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.

spasov21:12:23

Do you think the Clojure resources, like the for the Brave and True book would also teach me Clojurescript?

spasov21:12:43

I know there are some differences between the languages so I want to get that straight before I dive too deep into Clojure.

hiredman21:12:23

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

hiredman21:12:34

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

camdez21:12:53

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.

gdeer8121:12:30

@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

hlolli21:12:00

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?

shaun-mahood21:12:07

@spasov: https://github.com/magomimmo/modern-cljs is a good resource for ClojureScript as well

hiredman21:12:35

@hlolli check out instanparse

hiredman21:12:54

https://github.com/hiredman/prubasic is a toy compiler that uses instaparse

hlolli21:12:58

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.

hlolli21:12:32

Well, my conclusion is not build on much experience, but thanks, I look into this.

hiredman21:12:37

what does that mean?

hiredman21:12:47

"I prefer to extend-types to create my own parse-tree that use bison-ish rules to make them."

hiredman21:12:15

it sounds like you want an evaluator or a compiler, not a parser

hiredman21:12:43

if you are dealing with defrecords and deftypes and a tree in memory already, then you are already parsed

hlolli21:12:51

I'd rather want (+ 2 2) to become [:fn "sum" 2 2] => int = 2 + 2 (in target language)

hlolli21:12:55

so I dont want to work with strings

hiredman21:12:28

sure, not really parsing, tree rewriting

hlolli21:12:01

yes I may be looking for evaluator. So I ask for understanding for the lack of my academical knowledge in computer science 🙂

hiredman21:12:33

so tree rewriting is going to be a function from input tree to output tree, usually a recursive function

hlolli21:12:35

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.

hiredman21:12:54

I would look at something like http://lisperator.net/pltut/, and just skip the parsing prelude

hlolli21:12:27

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.

thegeez23:12:24

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

jrheard23:12:07

@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