Fork me on GitHub

hiccup expects vectors to start with tags


you are passing in a vector [(html ... that is a tag and a body


So what should I do instead?


don't do that


you likely can get rid of both the wrapping vector and the extra call to html


(defn home
                  [:h1.display3 "Hello there!"]]


The above produces this error "[:div.container [:h1.display3 "Hello there!"]] is not a valid element name."


(defn home
                  [:h1.display3 "Hello there!"]]


Ah ha! The above works

Rowan Barnard02:08:27

Hi all, I've been learning from the book Getting Clojure the past few weeks and I am just running a code example but not getting the results as expected from the text. Here is the code: (​defn​ chatty-vector [] (println ​"Here we go!"​) [1 2 3])

Rowan Barnard02:08:10

Followed by: (​def​ s (lazy-seq (chatty-vector))) and (first s)

Rowan Barnard02:08:34

Is this some behaviour that is changed in Clojure since the book came out or perhaps an error in the book?


how do i import or require a protocol from a different namespace?


just require the namespace in which they are defined


ope, okay. got myself confused with records and importing. thanks


Does anyone know the book Rich is talking about in Are we there yet?


(here's the transcript of Rich's talk -- that site has transcripts of several other talks by him and others)

Jelle Licht12:08:01

how can I express the following (Java) method annotation @Plan([email protected](factchanged="time")) in Clojure? So how do I express the 'nested-ness' of these annotations?


do protocol interfaces support variable argument lists yet? or is this ( still the best work around?


reasoning: i have a macro that creates an if branch, where it either adds or doesn't add a specific call in the parameter list. this works in "normal" function calls because parameter length isn't checked unless execute. but in a protocol method, the parameter length is checked at compile. I can add an extra method signature that has a plz-dont-use parameter, but that feels like it's opening me up to bugs in the future.


code example, from after macro expansion:

(if use-eid#
  (handler (first costs) state side new-eid# card actions)
  (handler (first costs) state side new-eid# (make-eid state eid) card actions))


handler here is the protocol method


no, they do not support varargs

Scott Starkey19:08:50

Hi folks - I’m working on a game. I have a sequence of 16 vectors - 4 of one set of keys, 4 of another set of keys:

([:a :w] [:a :x] [:a :y] [:a :z] [:b :w] ... [:d :z])
(Note: The data won’t be neatly ordered like this.) I’d like to think of this data as 4 rows x 4 columns. I’ve figured out how to evaluate the rows for a test condition, but I’m having problems evaluating the columns. Maybe it would be easier to turn the grid 90° and then just use the same tests for the rows. Any thoughts on how to tackle this problem?


a row is (partition 4 coll), right?


so a column within a row would be (nth row index)


where index is a number between 0 and 3


oh, you're asking about the entire column i bet

Scott Starkey20:08:02

yes, the whole column


row * number-of-columns + column is the formula for each cell in the column


forgot to mention, lol, number-of-columns is 1-indexed and column is 0-indexed


(1-indexed isn't quite correct, it's just the natural means of counting)

Scott Starkey20:08:02

Maybe a couple of nested for statements?


that could work!


if you don't have substructure, you want a single for comprehension with multiple clauses

👆 1

in C / Java "for" is a statement that makes a loop, in Clojure it's a comprehension that generates a lazy sequence


we don't have statements


and if you're selecting a single column, you only need a single clause: (for [r (range 4)] (nth coll (+ 3 (* r 4))))


@scotto if you store the data in a more structured way, the form you present here is easy to derive - is there a reason it needs to be spread out like this?

Scott Starkey20:08:08

No, @noisesmith I could structure it differently if that would help things.


the non-math way would be (->> data (partition 4) (map #(nth % 3)))

👍 1

when it's only 16 items long, seems like not much to be gained by keeping it as a 1-d array


consider for example {:a {:w {} :x {} :y {} :z {}} :b {:w {} :x ... ...} ... ... :d {... ... :z {}}


depending on what you are using the data for - this structure is friendly for get-in for finding data at a specific nested index (and update via update-in or assoc-in)

Scott Starkey20:08:03

Here’s the thing - I want to make a test to see if there are 3 in a row of one of the keys, vertical or horizontal. I am wanting to filter/remove those from the possible permutations. There are a metric-butt-load of permutations, effectively a lazy sequence.

(combo/count-permutations tiles)
  ; => 20922789888000


clearly I didn't understand what you were doing here

Scott Starkey20:08:41

sorry! My fault.


you can use (partition 3 1 ...) and map a function that detects repeats of column or row


that might not be straightforward to apply at the filtering step though

Scott Starkey20:08:37

Yeah, I already have the function working that detects if 3 of a sequence of 4 is a match of either key.

Scott Starkey20:08:57

But only for rows.

Scott Starkey20:08:57

Hell, it might be easier to make a rotate 90 degrees function that takes the sequence [%1 %2 %3 %4 %5…. %16] and converts it to [%1 %5 %9 %13 %2 … %16]. I can hand-code that but it seems icky.

Scott Starkey20:08:06

OK, I managed to rotate it using the for statements mentioned above. Onward!

(defn rot90 [s]
  "Takes a sequence of 16 vector pairs and rotates it 90 degrees."
  (into [] (for [x (range 4)] (into [] (for [y (range 4)] (nth s (+ x (* y 4))))))))


@scotto does the same thing, more idiomatic:

(defn rot-90 [s] (apply mapv vector (partition 4 s)))


also it's immediately obvious how to parameterize it if your size ever changes from 4

Scott Starkey20:08:32

(not familiar with the mapv function… Looking that bad-boy up.)


map, apply, reduce, lifeblood of the sequentialist


don't you mean the cons-equentialist?

😄 1