Fork me on GitHub
#beginners
<
2016-01-21
>
slester00:01:31

@meow: that's what happened, but by that point my functions were all interdependent, which led me to my current problem 😞

meow00:01:08

you could post some code here or in #C053PTJE6

meow00:01:38

reading other Clojure code is also good

meow00:01:03

find devs that you admire and read their code

slester00:01:50

Thanks, added to #C053PTJE6 😄

slester00:01:56

For some unlucky person to sift through :[

eggsyntax02:01:19

@slester: at first look, is this the most key line making it hard to prevent circular deps? updated-state (-> state check-minister check-princess check-end-game)

slester02:01:17

@eggsyntax: not exclusively, there are lots of others (actions and gameplay) that are interdependent

eggsyntax02:01:43

Yeah, I can see how some of it could be difficult to untangle. I suspect a layer of abstraction over the actions -- so that you can essentially program to an interface in your gameplay fns -- might go a long way. And possibly the same thing on the other side, so that if actions need to trigger gameplay fns, they're calling an interface.

eggsyntax02:01:08

The code itself seems pretty well-written; the rules of the game themselves make it an inherently tangly problem. I think it can definitely be decomplected, but I don't see a single silver-bullet solution.

eggsyntax02:01:26

(& to be clear, I'd implement those interfaces using protocols [possibly deftypes as well, but there might not be much need for them here].)

eggsyntax02:01:46

@slester: Whoops, meant to post all that in #C053PTJE6, but I guess here's just as good since there hasn't actually been much discussion yet in #C053PTJE6.

ajmagnifico16:01:40

Quick Question:

ajmagnifico16:01:49

(> 5 2) yields true

ajmagnifico16:01:56

(> "b" "a") gives an error

ajmagnifico16:01:11

What is the idiomatic way to compare strings?

ajmagnifico16:01:19

Do I need to hack something together with (compare) ?

eggsyntax16:01:32

Hmm. (> “b” “a”) works fine for me in planck.

mfikes16:01:02

But if you do (doc >) you will see it is for nums

eggsyntax16:01:03

That may be a JS/Java distinction, though.

eggsyntax16:01:28

Yeah, I get the exception in clj.

ajmagnifico16:01:30

Yeah, in emacs/cider at the repl I just get an error

ajmagnifico16:01:53

So here's what I did, let me know if you think it's too terrible:

eggsyntax16:01:01

(compare “a” “b”) seems to do it.

ajmagnifico16:01:13

(defn C>
  ([x] true)
  ([x y] (> (compare x y) 0)))

eggsyntax16:01:02

I bet there’s a more elegant way to do it, but that seems reasonable.

ajmagnifico16:01:16

yeah, it looks ugly to me, but it seems to work

ajmagnifico16:01:34

I was surprised though that the > and < functions don't generalize to other data types like = does

mfikes17:01:52

Perhaps <, >, and == can be thought of as going together in that they work with nums.

meow17:01:35

I suspect it might be either adherence to the precedent set by Clojure and/or desire for performance optimization.

mfikes17:01:54

Yeah, must not have come from Common Lisp, with eq, eql, equal, equalp, etc.

donaldball17:01:26

I suspect it’s half that those operators predate protocols, and half that I suspect Rich has no interest in choosing which ordering is best for sets that can defensibly have multiple order fns

meow17:01:47

¯\(ツ)

stopa17:01:01

Hey everyone, I have a function like this ->

(defn body->multipart [xs]
  (let [res (MimeMultipart.)]
    (for [{:keys [body content-type]} xs]
      (let [part-fn (condp string/starts-with? content-type
                      "text" text-part
                      data-part)]
        (.addBodyPart res (part-fn body))))
    res))
When I do (.getCount (body->multipart [{:content-type "text" :body "hi"}])) I get 0, meaning that no body parts were added. Now, If I manually do this in the repl --
(def res (MimeMultipart.))

(for [{:keys [body content-type]} xs]
  (let [part-fn (condp string/starts-with? content-type
                  "text" text-part
                  data-part)]
    (.addBodyPart res (part-fn body))))

(.getCount res) ;; 1
I am sure I am missing something nooby. Any thoughts?

mfikes17:01:40

Try replacing for with doseq

stopa17:01:58

ah! thanks

mfikes17:01:28

Hopefully it is a drop-in replacement given doseq works like for.

stopa17:01:02

worked like a charm. thanks @mfikes

iha218:01:46

i need some help with loading files in the lein repl so I can use the functions in it.

jack_liang18:01:57

hi, i am new to clojure and trying to learn the language thing is i dont know if im being too syntax oriented i cant seem to find much resources regarding how the loops work or conditionals work perhaps im looking in the wrong place any ideas?

jack_liang18:01:40

im more use to learning by example with a bit of explanation

iha218:01:18

have you taken a look at clojure koans?

mfikes18:01:55

@iha2: Two things worth checking out are require and load-file. They can be invoked at the REPL and can load code.

iha218:01:58

@mfikes: I use load-file a lot but it won’t let me run the individual functions defined

iha218:01:33

@mfikes: load file sort of runs the whole file and returns the output, require for me can’t find the file on classpath even as load-file does and works

mfikes18:01:08

@iha2: does the file you are loading with load-file define the functions in a namespace? (Perhaps you need to access the functions using a namespace qualifier.)

mfikes18:01:56

@iha: require usually indicates where it looked if it failed.

iha218:01:49

for require it defines the classpath as clojure.lang.RT.load

iha218:01:55

if that makes sense

mfikes18:01:44

@iha2: That 4-line snippet is the file you are loading?

iha218:01:03

The namespace definition anyway

mfikes18:01:51

@iha2: If there is a function defined in that file, after doing (load-file <filename>), you should be able to call the function using (hiclustering/function-name …)

iha218:01:43

@mfikes worked like a charm:+1:

iha218:01:00

@mfikes thanks a lot man!

Tim19:01:52

are the square brackets in clojure [] reader macros?

jonahbenton19:01:43

hey @tmtwd: square brackets are not reader macros; reader macro behavior is triggered by other specific characters, e.g. http://clojure.org/reference/reader#macrochars

seancorfield19:01:16

@tmtwd: [] indicate vectors (as opposed to lists).

seancorfield19:01:29

Clojure has more data structure types than "regular" Lisp.

Tim19:01:06

why doesn’t scheme or CL have vectors / arrays?

Tim19:01:26

isn’t that something all languages have?

Tim19:01:37

why would they limit themselves to linked lists

seanwalker19:01:56

They have vectors, arrays, maps, etc but no literal syntax for them

Tim19:01:07

ah true. I can’t believe I never noticed that. I think because sicp doesn’t cover it

tord20:01:42

I don't know about Scheme, but CL has literal syntax for vectors and arrays.

clojuregeek20:01:42

@joshua.d.horwitz: i made a list of getting started things that I am using to learn http://blog.clojuregeek.com/getting-started

clojuregeek20:01:05

I think the clojure koans are a better starting place then 4clojure

slester22:01:49

4clojure is getting hard, but I'm persevering 😞

slester22:01:25

"Flatten a sequence" is really not... "easy" to me

chadhs23:01:05

bummer http://clojuredocs.org/clojure.data/diff doesn’t handle comparing a set vs an empty set well

chadhs23:01:15

complains about null pointer 😞

chadhs23:01:22

time to rethink my approach

chadhs23:01:17

ill check it out shaun thanks, i also may have spoke too soon and my function may have been trying to turn nil into a set… i’ll report back

chadhs23:01:16

@slester: are you enjoying working through 4clojure? i find i get stuck as well but am trying to leverage this channel and http://clojuredocs.org for ideas etc