Fork me on GitHub
#clojure
<
2015-11-14
>
domkm00:11:16

Question for Prismatic Schema users: How would you create a schema that matches a sequence where the first element is a keyword and the rest, if present, can be anything? I can do it using pred but that seems hacky.

mccraigmccraig00:11:34

@domkm: [s/Keyword s/Any]

domkm00:11:20

@mccraigmccraig: Unfortunately that doesn't work: Sequence schema [Keyword Any] does not match [one* optional* rest-schema?]

mccraigmccraig00:11:16

oops - i'm not at a repl now so can't figure out what i did wrong

mccraigmccraig00:11:25

try wrapping the s/Keyword in s/one

domkm00:11:37

@mccraigmccraig: That worked. Thanks!

lambeta03:11:39

Hi divemind, anyone knows how to check if a two-dimensional array contains one-dimensional array like [[0 0 0]] should contain [0 0 0]? I tried (every? (apply hash-set [[0 0 0]]) [0 0 0]) and it returns false.

Alex Miller (Clojure team)03:11:14

contains? is the best way to check for containment in a set: (contains? (apply hash-set [[0 0 0]]) [0 0 0])

lambeta03:11:20

and then I tried (every? (apply hash-set [[0 0 0]]) ‘([0 0 0])) it return true.

Alex Miller (Clojure team)03:11:37

every? takes a predicate that is applied to every element in the collection - you're using the set as the predicate and applying it to 0, 0, and 0 in the first example

lambeta03:11:20

sure. thanks

kardan06:11:16

Is it not possible to have a :or on the key in a map with core.match like (match [m] [{(:or :ok :err)_ }] :a)? I do get the example from the docs with :or on the key working..

cch114:11:57

Is this the appropriate channel in which to ask (advanced) java interop questions?

cch115:11:31

I’ve tried every combination of dot operators on earth to no avail. I’m initializing the library first,and I’ve tried going through this (singleton?) instance: (org.abstractj.kalium.NaCl/sodium)

agile_geek15:11:35

@cch1: Have you tried NaCl$Sodium/BOXZERO_BYTES ?

agile_geek15:11:00

in full - org.abstractj.kalium.NaCl$Sodium/BOXZERO_BYTES

cch115:11:57

@agile_geek: that did it. I know that I tried at least one variation with an inner class, but that one solved the problem. THanks,

roelof16:11:09

Is the brave book a good book to learn clojure the right way ?

binduwavell17:11:04

@roelof, I'm a newbie like you and working my way through Clojure for the Brave and True. I have found the intro material to be very good. It has sucked a bit for me to learn Emacs (I've been a vi guy for many years) as it adds a secondary cognitive load on top of the already daunting task of learning clojure/functioanl-thinking... To be clear the book makes it clear that Emacs is not a requirement and I believe most professional Clojure folks use Emacs... However, it doesn't provide enough details on how to use something more simple for a beginner. At the end of the day I'm not sure if I like this or not as I'm not done with the book... I found a couple chapters started glossing over stuff, missing parts of examples, which makes it hard to type in some things (even peg thing is slightly incomplete.) I would prefer that all of the chapters be consistent in this regard (i.e. not skipping stuff)... Having said that, I love that the text is littered with pop-culture references and I find the examples more engaging given this approach... Any way, from what I've read, many well respected Clojure folks suggest this book for beginners...

binduwavell17:11:48

@roelof also there is a beginners channel here in the clojurians slack. It was not clear to me when I logged in, it turns out there are hundreds of channels and the beginners area is a good place to post newb questions, some super-smart/experienced folks monitor and answer questions there.

roelof17:11:43

binduwavell: oke, and where can I find the beginners channel and have you find another book or did you finisched learning clojure with this book

binduwavell17:11:16

@roelof if you are using the web interface to slack just click the channels header on the left that will help you browse/search all channels.

binduwavell17:11:18

@roelof I most definitely have not completed learning clojure. Clojure for the Brave and True is the first book I've read (have read some online and done some koans, etc before diving into this book.) I'm not even done reading it simple_smile I have heard amazing things about The Joy of Clojure, but everyone says it's not good as a first book. My plan is to finish Clojure for the Brave and True, maybe do some simple projects with Clojure/Clojurescript and then read TJoC.

roelof17:11:50

sounds like a good plan

roelof17:11:08

binduwavell: are you working on Linux or a windows user ?

twillis17:11:13

I recently got the book clojure applied and it's an excellent second book after you know the language. http://www.amazon.com/Clojure-Applied-Practitioner-Ben-Vandgrift/dp/1680500740/ref=sr_1_1?ie=UTF8&amp;qid=1447522554&amp;sr=8-1&amp;keywords=clojure+applied and there's a lot of good stuff in the clojure cookbook too https://github.com/clojure-cookbook/clojure-cookbook

Tim19:11:10

clojure applied seems good

Tim19:11:22

I only really just started it though

anshbansal20:11:31

Is Clojurescript meant for front end?

jaen20:11:25

That's an interesting question. I though Clojurescript was meant mainly for the frontend and all the rest was just a side effect of Javascript reaching to other places as well.

anshbansal20:11:49

@jaen: I am a beginner in Clojure land so was just not sure whether it is meant to replace only javascript or everything on HTML/CSS

anshbansal20:11:56

I am assuming only Javascript

jaen20:11:03

Well, when writing with React you have templating languages that use Clojure syntax (for example hiccup-like sablono and enlive-like kioo), so you can at least replace HTML with it as well.

jaen20:11:44

I've heard of Garden that lets you preprocess CSS using Clojure syntax as well, but I don't know whether it can run in just Clojurescript, or you need to run it in Clojure beforehand.

jaen20:11:40

That said you can keep your usual webdevelopment habits as well. For example boot has a nice boot-middleman plugin that lets you use Ruby's middleman for HTML & CSS stuff and Clojurescript for JS-replacement only.

jaen20:11:12

That said using Clojurescript with React is the most popular nowadays, so I guess it encompasses JS+HTML part from the three.

anshbansal21:11:20

Leaving Clojurescript aside for a moment if I just want to use Clojure for the back-end what's the easiest way to get a server up in Clojure?

jaen21:11:00

But to boil it down for you - you probably want to try Luminus.

jaen21:11:32

It's the closest thing Clojure has to being batteries-included like Rails. And after you get comfortable with basics you can explore other libraries.

jaen21:11:01

Luminus also has a book about it IIRC - http://shop.oreilly.com/product/9781680500820.do

jaen21:11:21

(there's also 1st edition, but 2nd will probably be more up to date)

anshbansal21:11:33

@jaen: Thanks a ton. You saved me a lot of headache. I came across an idea and wanted to try and make it in Clojure so I can get a project started. Otherwise learning Clojure via tutorials only was putting me off a bit

jaen21:11:08

Well, setting up your own project, choosing libraries and so on is a bit tedious, even when you have some experience with Clojure and ecosystem.

jaen21:11:21

For a beginner Luminus simplifies that part away

anshbansal21:11:22

One more thing. Is it possible to configure lein to use libraries from Maven Local if they are present there? Any idea?

jaen21:11:31

I've never used Java, so I don't know for sure

jaen21:11:47

But I think both leiningen and boot use the local .m2 dir

eraserhd21:11:55

@anshbansal: I think that happens automatically.

jaen21:11:03

There's also the concept of snapshot dependencies in leiningen if you need to use development version of library not yet packaged into a jar

anshbansal21:11:35

I checked the timestamps and it is downloading in local .m2. Nice

jaen21:11:30

@anshbansal: one thing more - Luminus is geared somewhat more towards classic multi-page apps, liek Rails (that is not to say it can't support Clojurescript and SPA, but IMO the focus is clear). If you're interested in doing SPAs with Clojurescript it makes sense to take a look at boot (alternative build tool to leningen) which IMO feels really better to work with if you're doing Clojurescript. You can take a look at sample projects here - https://github.com/martinklepsch/tenzing - and here - https://github.com/Deraen/saapas.

jaen21:11:08

Though it probably makes sense to play with Luminus first a bit and move over once you understand the basics.