Nice! Thank you both for the simple answer. Again I find that I
overcomplicate things in Clojure. :)

-thomas

On Wed, May 19, 2010 at 1:14 PM, Laurent PETIT <laurent.pe...@gmail.com> wrote:
> 2010/5/19 Thomas Kjeldahl Nilsson <tho...@kjeldahlnilsson.net>:
>> Hello, newbie question here. :)
>>
>> I'm writing a Tetris game to teach myself Clojure, and I'm trying to
>> keep the code ideomatic as I go along.
>> One of the most basic parts of the underlying model is representing
>> the pieces and playing field as two dimensional matrices.
>>
>> This is an L shaped playing piece (represented by a two dimensional
>> vector literal):
>>
>> (def L-shape
>> [
>>  [0 1 0 0]
>>  [0 1 0 0]
>>  [0 1 1 0]
>>  [0 0 0 0]
>> ])
>>
>> I want to check if other matrices of same size have the same shape,
>> ie. are the 1's and 0's in the same places in the compared matrix?
>>
>> I suppose the most straight-forward way is write a function which
>> steps through the two matrices simultaneously, comparing
>> corresponding elements one by one.
>>
>> My question: is there a more elegant way of determining equivalence of
>> collection structures like these in Clojure?
>
> Ooh yes, just use = on the two elements you want to compare:
>
> user=> (= [[0 1 0 0] [0 1 0 0]] [[1 0 0 0] [0 1 0 0]])
> false
> user=> (= [[0 1 0 0] [0 1 0 0]] [[0 1 0 0] [0 1 0 0]])
> true
> user=>
>
> Apart from the reference types (agents, atoms, refs, vars), every
> datastructure clojure provides to you has "value" semantics, not
> object identity semantics.
> And of course composing clojure datastructures preserves the "value" 
> semantics.
>
> Welcome to the wonderful clojure world !
>
> --
> Laurent
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to