Fork me on GitHub
#beginners
<
2015-08-13
>
braai engineer06:08:57

What's the shortest way to add N values to a set using only core functions?

sveri06:08:19

petrus: not sure if this is the shortest, but it works: (reduce conj #{1 2 3} (range 55 60))

braai engineer06:08:53

looks like merge works! (merge #{1 2 3} 5 7) => #{7 1 3 2 5}

sveri06:08:12

true, merge is shorter

braai engineer06:08:59

I'd like to rotate a 2D vector by a rotation matrix without requiring huge matrix libraries. Is there a clever way to multiply a position vector like [-1 0] by a 90 deg rotation matrix like [[0 1] [-1 0]] in a terse way?

jeffmk06:08:31

@petrus: (into #{} (repeatedly rand)) ?

braai engineer06:08:58

So I guess this is pretty short:

(let [pos [0 -1]] ; position vector
  [(apply + (map * [0 -1] pos)) ; colums of 90 deg rotation matrix
   (apply + (map * [1 0] pos))])
=> [1 0] ; rotated 90 deg clockwise

braai engineer06:08:32

Is there a way to add state to cycle in Clojure?

braai engineer06:08:23

I guess a circular list.

jeffmk06:08:45

Why would you need state? Couldn’t you use take and take-last to emulate it since it’s infinite?

escherize10:08:49

Best way to case insensitive string compare?

escherize10:08:20

I'm thinking: #(= (str/upper-case %1) (str/upper-case %2))

dapi13:08:39

Hello all! What does keyword :- mean in the functions definition like this: (defn func [schema coercion-matcher :- CoercionMatcher] … ) ?

dapi13:08:11

Yes, it's from Prismatic/schema, but I can't understand what this keyword :- does mean. Is it clojure-specific argument type or something user defined?

roberto13:08:43

it is part of schema

roberto13:08:10

it is specifying the type or in this case, the schema.

roberto13:08:36

from the example in the Readme:

(s/defn stamped-names :- StampedNames
  [names :- [s/Str]]
  (StampedNames. (str (System/currentTimeMillis)) names))

roberto13:08:03

it says, that the function stamped-names should return a value of type (or schema) StampedNames

roberto13:08:18

and that the argument names should be a string.

roberto13:08:37

the java equivalent: StampedNames stamped-names(String[] names);

dapi13:08:20

@roberto, thanks! I see it is behaviour of schema's def macro.

dwht15:08:40

Hello guys, could you help me. I have this code https://gist.github.com/anonymous/e9b1dbc20d382cfbacc7 When I try to write into file manually created vector everything looks good. But when I try to write vector that I received from file, I have a exception. But this vectors are equal.

surreal.analysis15:08:18

@dwht: Can you post /Users/dwht/Documents/artec-png/input/minus.png.h here?

dwht16:08:53

of course

dwht16:08:40

oh, I found my mistake