Fork me on GitHub
#clojure
<
2016-11-27
>
bja00:11:16

(defn signup-user [pgsql new-user] (when (s/validate schemas/User new-user) (sql/save pgsql new-user)))

tdantas00:11:52

cool ! and the error messages ?

bja00:11:54

I would have code that does that

bja00:11:04

and then I'd have a function higher up, that catches exceptions thrown

bja00:11:07

and builds the response

bja00:11:31

in particular, I'd define the exception handler in my routes.clj and this in my controllers.clj (or something similar)

tdantas00:11:33

so, my functions must throw an error ?

bja00:11:37

they don't have to

bja00:11:49

I find throwing with slingshot is nice

tdantas00:11:52

validate and save on your example

bja00:11:22

in my example, I'd expect validate to throw an exception if the user doesn't pass the schema check, and save to throw an error if the user already exists

tdantas00:11:55

interesting approach

bja00:11:08

(that's also exactly how I'd write my code in python or ruby, fwiw)

tdantas00:11:10

exception controlling the flow

tdantas00:11:25

in ruby ( active record ) we normally call valid? before the save!

bja00:11:30

(when (s/validate User new-user) ....) would validate before calling save

bja00:11:57

it's just the s/validate will return a truthy value (and thus execute the body) if the schema is valid, and it happens to throw an exception if new-user doesn't match that schema

bja00:11:13

but you can replace s/validate with whatever valid? you'd want to write

haywood00:11:29

Hey, I just created a new chestnut project via lein new chestnut my-project, but after adding datomic I get this error when trying to execute lein repl

Exception in thread "main" java.lang.ExceptionInInitializerError
	at clojure.main.<clinit>(main.java:20)
Caused by: java.lang.IllegalArgumentException: No matching ctor found for class clj_logging_config.log4j.proxy$org.apache.log4j.WriterAppender$ff19274a, compiling:(clj_logging_config/log4j.clj:37:18)

haywood00:11:38

I've been stumped for the past couple of hours, I tried adding the log4j as a dependency, as well as following the directions here http://docs.datomic.com/configuring-logging.html

haywood00:11:53

Came here as a last resort in case anyone had an idea 😄

bja00:11:19

@haywood I don't know for certain, but that looks like it might be a library version conflict. you might run lein deps :tree and scan for complaints around log4j and/or clj-logging-config

haywood00:11:03

ah, wonderful will try, thank you

haywood00:11:41

looks like possibly clashing with ring.middleware.logger

haywood00:11:49

so in this case I can use exclusion on that package?

bja01:11:30

you can pin ring.middleware.logger and add an :exclusions [....] to that

martinklepsch05:11:43

Thanks for the pointers @dominicm and @hiredman! Pretty is nice for exceptions but not much beyond that as far as I can tell. I'll also take a look at fipp and that paper. Maybe an interesting project...

roelofw10:11:09

Is there some more info then the spec page to learn more about spec

Alex Miller (Clojure team)13:11:57

There are also a number of blogs and screencasts at http://blog.cognitect.com

Alex Miller (Clojure team)13:11:24

I'm working on a chapter for the next edition of Programming Clojure but it will be a while before that's available

roelofw15:11:06

Are there here people who develop in Linux.if so, which distro do you use ?

roelofw15:11:13

@alexmiller thanks. I will read it

Alex Miller (Clojure team)15:11:25

That's weird and it does look similar to the referenced bug

Alex Miller (Clojure team)15:11:17

You're sure you are using latest Clojure? You can use clojure-version to check

Alex Miller (Clojure team)15:11:53

Sorry, stars around that as it's a dynamic variable

Alex Miller (Clojure team)15:11:34

If you're reproducing on 1.8 or 1.9, prob should file a ticket in jira for it

find_my_way15:11:57

I’m new to clojure and I specify the Clojure version in lein’s project.clj

Alex Miller (Clojure team)15:11:47

Yeah, checking at the repl can help you verify that it matches what you think it is

find_my_way15:11:59

Ah, I reproduce it too...

find_my_way15:11:32

I’m sorry, maybe I confused the versions...

nha15:11:29

Seems to work the second time though

find_my_way15:11:43

yes, but I really don’t understand why

roelofw16:11:06

@alexmiller can the spec be good for a beginner to use for solving 4clojure puzzles

roelofw16:11:15

oke, then I will not use it for that. then I wait till I make "real" programms like a web app

jrheard18:11:26

counterpoint - i had a fun time using spec to solve http://adventofcode.com/2015 problems - it wasn’t at all necessary to use spec for any of them really, but i found it a useful exercise for getting muscle memory / familiarity with writing+using specs

jrheard18:11:53

i was a beginner to spec but not a beginner to clojure, so my experience with advent of code may not be relevant to the discussion

lvh18:11:06

Is there a reasonable way to get all of the possible ways a substring can be replaced by a different substring? I.e. ab -> xy, ababab -> [xyabab, abxyabab, …] (at most one). I’m guessing this is just going to be manual coding + subs

gfredericks23:11:23

Doesn't sound too complicated

gfredericks23:11:51

Just gotta think about the edge cases around overlapping matches