Fork me on GitHub
#beginners
<
2016-02-09
>
Kamuela00:02:33

If I pick up a book circa 2012, am I missing out a lot or possibly learning a lot of bad and outdated things?

seancorfield01:02:56

Depends on the book...

seancorfield01:02:22

There certainly has been quite a lot of movement in the ecosystem since then...

seancorfield01:02:06

It’s likely that books targets Clojure 1.3 or maybe 1.4 so you can see what’s been added since here https://github.com/clojure/clojure/blob/master/changes.md @kamuela

Tim03:02:53

(compojure/POST "/:foo" [x y & z :as request]
    (println "testing 1 12 3")
    (def yo request)
    (str "x-> " x "\ny-> " y "\nz-> " z "\nrequest-map:\n" request))
how come this post request works fine, but
(compojure/POST "/:foo" request
     (let [[x y & z] request]
       (println "testing 1 12 3")
       (def yo request)
       (str "x-> " x "\ny-> " y "\nz-> " z "\nrequest-map:\n" request)))
this one doesn’t?

Tim03:02:14

and I get this error

<h2>HTTP ERROR: 500</h2>
<p>Problem accessing /arg. Reason:
<pre>    nth not supported on this type: PersistentHashMap</pre></p>

seancorfield04:02:25

@tmtwd: I'm having a hard time seeing a difference between those two code fragments... did you mean to post two different things?

Tim04:02:23

(compojure/POST "/:foo" request
     (let [[x y & z] request]
       (println "testing 1 12 3")
       (def yo request)
       (str "x-> " x "\ny-> " y "\nz-> " z "\nrequest-map:\n" request)))

Tim04:02:28

sorry I meant to post that

Tim04:02:39

this one doesn’t work

Tim04:02:30

(I updated the post to fix the error)

seancorfield04:02:30

It's a macro, so normal Clojure destructuring doesn't apply directly.

Tim04:02:14

ah I see

Tim04:02:42

it maps directly to the params map

seancorfield04:02:11

(I didn't know, I had to go look it up)

pvinis09:02:56

maybe it will be interesting with clojure

olegakbarov20:02:12

(if (t/before? (t/now) (f/parse iso-8601 starts_at))
                         "Match scheduled"
                         (if (t/before? (f/parse iso-8601 ends_at) (t/now)) "Match is over" "Match is in progress”))
any ideas why this incorrect ?

olegakbarov20:02:58

nesting of ifs is not good idea i guess, but the problem is in weird behaviour

olegakbarov20:02:55

also ends_at and starts_at are valid dates

meow21:02:43

nesting is fine

meow21:02:44

make sure you understand if and when and how to execute more than one form

olegakbarov21:02:36

> how to execute more than one form

olegakbarov21:02:55

what do you mean? ain’t forms evaluated recursively?

olegakbarov21:02:23

like (3rd(2nd(1st)))

meow21:02:04

that's not recursion

lucien.knechtli21:02:26

(that's nesting)

olegakbarov21:02:28

well, but the order is correct?

lucien.knechtli21:02:42

can you give some examples where it doesn't work as expected?

lucien.knechtli21:02:07

just plugging in values seems to work for me

olegakbarov21:02:40

i exchange before? to after? in first if and get either a string or empty in logger

olegakbarov21:02:53

seems like a really weird behavior, becaiuse i expect a least false and evaluation of next if (which should return string too)

olegakbarov21:02:47

i for now ended up with (if (t/before? (t/now) (f/parse iso-8601 starts_at)) "Match scheduled" "Match is over”) — but this doesn’t cover my case

olegakbarov21:02:57

and i want to get to the bottom of it

olegakbarov21:02:15

to gain deeper understanding of how things work in clojure

lucien.knechtli21:02:24

that doesn't make any sense

lucien.knechtli21:02:44

(if true (print "a") (if true (print "b") (print "c"))) ;; prints a
(if false (print "a") (if true (print "b") (print "c"))) ;; prints b
(if false (print "a") (if false (print "b") (print "c"))) ;; prints c

lucien.knechtli21:02:03

that's as basic as it gets

meow21:02:35

do two things in your else case, for illustration purposes

lucien.knechtli21:02:58

if you print the values you'r comparing (after parsing), are they the same type as t/now?

olegakbarov21:02:11

they are #object[org.joda.time.DateTime 0x1fbd558d "2016-02-07T15:30:00.000Z”]

olegakbarov21:02:40

about else — are there even at all else in clojure?

olegakbarov21:02:46

i can’t find reference

olegakbarov21:02:11

(if (t/before? (t/now) (f/parse iso-8601 starts_at)) "Match scheduled" "Match is over”)

olegakbarov21:02:16

this works as expected

bronsa21:02:16

if(test) { return x; } else { return y; } in clojure translates to (if test x y)

olegakbarov21:02:42

yep, this is how i understand it (and appreciate 😅 )

olegakbarov21:02:04

this returns nothing to logger

(if (t/before? (t/now) (f/parse iso-8601 starts_at)) "Match scheduled"
                          ((t/after? (t/now) (f/parse iso-8601 ends_at)) "Match is in progress"
                          "Match is over”))

olegakbarov21:02:14

:thinking_face:

lucien.knechtli21:02:35

you have an extra wrapping paren?

lucien.knechtli21:02:48

on the second line

lucien.knechtli21:02:51

or is that a missing if

lucien.knechtli22:02:16

yea you forgot the if

olegakbarov22:02:50

yes thank you

olegakbarov22:02:57

but surprisingly

olegakbarov22:02:02

result is the same

olegakbarov22:02:42

so i got and empy res with this too

(if (t/before? (t/now) (f/parse iso-8601 starts_at)) "Match scheduled"
                          (if (t/after? (t/now) (f/parse iso-8601 ends_at)) "Match is in progress"
                          "Match is over”))

solicode22:02:39

Empty result? You’re getting nil when you run that code? I don’t see how that’s possible because all paths return a string.

lucien.knechtli22:02:43

are you writing this stuff directly into a repl as is, with preset values?

lucien.knechtli22:02:48

and making sure that each inner expression evaluates as you expect it would?

olegakbarov22:02:47

thank you, i’ll try this in repl (probably should do it all of the time before asking)

akiva23:02:23

@olegakbarov, always ask if you want. There’s no judgement here. I’m pretty good at Clojure and I hang out here because I help when I can and I end up learning a lot too. It’s a good thing.

slester23:02:21

Yeah, I like actually knowing the answer sometimes 😄