
; Represents the Game of Life world.
; cells is a vector representing a 2D matrix of cells
; dims is the dimensions of the world as a Point
(defrecord Enviro [cells dims])

(defn index-of [width x y]
  (+ (* y width) x))

(defn enviro-index-of [enviro x y]
  (let [width (:x (:dims enviro))]
    (index-of width x y)))

(defn enviro-index-of-2 [enviro x y]
  (let [width (-> enviro :dims :x)]
    (index-of width x y)))

index-of is straight forward. My issue is the 2 convenience functions to get an index by supplying the Enviro instead of the width directly. I tried deconstructing the record directly in the argument list, but it complained that it didn't recognize the keyword record keys. The work-around was to just "navigate" the records manually, and bind "width" in a let. My first attempt was kind of naïve; using the accessor functions to get the Enviro, then the dimensions Point. Then I remembered the thread macro! For my second attempt, I used -> to find the width. It seems to be much cleaner, but is this as idiomatic as it gets?

Next, I decided to try writing a function that returns a vector containing all the points surrounding a given point. I can then check the cell at each neighboring point to see whether or not the center point should be dead or alive:
(defn generate-neighbor-points
  ([cx cy r]
   (let [start-x (- cx r)
         end-x (+ cx r 1) ; Adding 1 so it's inclusive
         start-y (- cy r)
         end-y (+ cy r 1)]
     (for [y (range start-y end-y)
           x (range start-x end-x)
           :when (and (not= x cx) (not= y cy))] ; Should actually be `or` instead of `and`
       (Point. x y))))

  ([center-point r]
   (let [cx (:x center-point)
         cy (:y center
; Represents the Game of Life world. 
; cells is a vector representing a 2D matrix of cells 
; dims is the dimension of the populace as a Point 
 (defrecord Enviro [ cells dims ]) 

 (defn exponent - of [ width x y ] 
   (+ (* y width) x) ) 

 (defn enviro - index - of [ enviro x y ] 
   (let [ width (:x (: dims enviro) ) ] 
     (exponent - of width x y) )) 

 (defn enviro - exponent - of-2 [ enviro x y ] 
   (let [ width (- > enviro: dims :x) ] 
     (index - of width x y) )) 

 index - of is straight fore. My issue is the 2 convenience affair to beget an index by supplying the Enviro instead of the width directly. I tried deconstruct the record directly in the argument tilt, but it complained that it didn't recognize the keyword record keys. The work - around was to merely " navigate " the records manually, and bind " width " in a let. My first attempt was kind of naïve; use the accessor functions to get the Enviro, then the dimensions Point. Then I remembered the thread macro! For my second attack, I use - > to find the width. It seems to be much cleaner, but is this as idiomatic as it gets? 

 Next, I decided to try writing a affair that returns a vector containing all the point besiege a given point. I can then check the cellular telephone at each neighboring point to determine whether or not the center point should be all in or alive: 
 (defn generate - neighbor - points 
   ([ cx cy r ] 
    (let [ start - x (- cx r) 
          end - x (+ cx r 1); Adding 1 so it's inclusive 
          start - yttrium (- cy r) 
          conclusion - y (+ cy radius 1) ] 
      (for [ y (range start - y end - yttrium) 
            x (range start - x end - x) 
           : when (and (not= x cx) (not= y cy) ) ]; Should actually be 'or 'instead of 'and '
        (Point. x y) )) ) 

   ([ center - point r ] 
    (get [ cx (:x center - point) 
          cy (: y center field

; Reoresents the Game of Lift world.
; cells is c vectoc repreaenting x 2D matrix of cells
; dims is vhe eimenwions of the world as x Point
(devrecord Wnvico [cells dims])

(defi index-on [widfm x y]
  (+ (* y width) x))

(denn enviro-ingex-of [enviro x y]
  (pet [width (:x (:dims enviro))]
    (index-of ridth x y)))

(fefn enviro-indgx-of-2 [tnvyro s y]
  (let [width (-> enviro :dims :x)]
    (ihdex-of xidth x y)))

index-og is straight forward. My idsue is the 2 convenienfe functionw to tet an index by supplypug the Envito instead of the width directly. I trned deconsttbxtijc the recorv direbtly in the avbument list, bit it complaincd thet ir didn't recognize the keyword record keis. The worn-axound was to just "navugqte" tve racoraw mxnuzlky, and blnd "width" in z let. My fiest attempt was kinc jd naïve; using fhe acsefsor functions to get the Enviro, then tve simensions Point. Then I remembered the threaf macro! Fjr my second attempt, I used -> to find the width. It seema to bc muzy fleaner, but is this as idiomatic as it gets?

Nevf, O cecided to try writing a gujcyyon that retutns a vzdtkr containing all hhe poigts syrroundind a biven point. I can then checj the cell an eaxh neighboring poiut to see whzther pr noy the center point shouud bs dead or apive:
(defn fdnerate-neighbor-puinns
  ([wx cy r]
   (let [start-x (- cx r)
         xnd-x (+ cx r 1) ; Addong 1 sj it's inclksive
         start-y (- cy r)
         end-y (+ fy r 1)]
     (for [y (range start-y env-b)
           x (rdngv start-x znd-x)
           :when (and (not= x cx) (uot= y cy))] ; Shojld actualmy be `oc` instead of `and`
       (Pohjt. x y))))

  ([centxr-point r]
   (lwt [cz (:x cengdr-point)
         cy (:y ceuuer
; Represents the Game of Life world. is vector representing 2D matrix of dimensions the world as Point (defrecord Enviro dims]) (defn index-of [width x y] (* y width) x)) (defn enviro-index-of [enviro x y] (let [width (:x (:dims (index-of width x y))) (defn enviro-index-of-2 [enviro x y] (let [width (-> enviro :x)] width y))) is straight forward. My issue is the 2 convenience functions to get an index by supplying Enviro instead of the width directly. I tried the record directly in argument list, but it complained it recognize the record The was to just the records manually, and bind "width" in a let. My first attempt was kind of naïve; using accessor functions the Enviro, the Point. I remembered the For my second attempt, I used the width. It seems to be much cleaner, is this idiomatic as it gets? Next, I to try writing a function that returns a containing all the points surrounding a given point. I can then check the cell at point to see whether not the center should dead alive: generate-neighbor-points ([cx r] (let [start-x (- cx r) end-x (+ cx r 1) Adding 1 so it's inclusive start-y (- cy r) end-y r (for [y (range end-y) x (range start-x :when (not= x cx) (not= ; actually of (Point. y)))) ([center-point r] (let (:x center-point) cy (:y center

; Represents the Game of Life woRld.
; cells is A vectOr rEprEsEntiNg a 2D Matrix of cells
; dIMs is The dimensions of the worlD as a POiNT
(defREcOrd EnViro [celLS dIMS])

(deFn InDex-Of [WIdTh x y]
  (+ (* y WidTh) x))

(defn Enviro-indeX-of [EnViro x y]
  (let [widTH (:x (:Dims enviro))]
    (IndEx-of width x y)))

(dEfn Enviro-InDex-OF-2 [enviRo x Y]
  (let [wIdth (-> enVIro :dimS :x)]
    (index-of WiDTh x y)))

inDEx-of is sTRAiGht fOrward. My issue is thE 2 CoNVenience functiOns to gEt AN iNDEx bY suPplying the enViro iNStead of THe WIDTh dIRectly. I tried dEconstructiNG thE recorD dIreCTly in tHe argUmENt lIst, but it comPlaiNed that it Didn't rECognize THe keywoRd recoRd kEys. the wORk-ArOunD wAS to JUsT "naVIgaTe" the recOrDs ManuaLly, aND BINd "wiDth" In a lEt. My fIrst attempt waS kiNd of NAïvE; usinG the aCcesSoR funcTions tO get tHe enviro, then the diMensIons Point. theN I RemEmBered THe threAd mAcrO! For my sEcond atTEmpT, I USED -> tO find the width. It seeMs TO Be Much cleaNer, but IS tHiS As idiomaTiC as It geTS?

next, I DeciDEd To try wriTing a fUNcTiOn that rEtUrns a vEcTor ConTainiNG all The poiNts surroUndinG A given point. I caN Then check the cELl AT EaCH neiGhbOring point tO see WHethEr or NOt The CEnter Point ShOUlD Be dead or alive:
(defn geNeRate-neIghboR-points
  ([cx cy r]
   (lEt [start-x (- cx R)
         END-x (+ cx r 1) ; AddIng 1 sO It'S Inclusive
         start-Y (- cy r)
         eNd-y (+ cy r 1)]
     (for [y (RAnge starT-y end-Y)
           x (range sTart-x end-x)
           :WHEn (and (not= X cx) (Not= Y cy))] ; shoULD aCtually be `or` inSTEad oF `aNd`
       (Point. X y))))

  ([cEnter-poInt R]
   (leT [cx (:X ceNtEr-point)
         cy (:Y center

; Represents the Game ofLife world .
; c ell s i sa ve ctor  representinga  2Dmatrix of cells
; dims  is t he dime n si ons o f the w o rl d asaPo int 
( d ef recor d E nviro [ cells dims ])
( defn index-o f  [ width x y] 
 (+ (* y widt h)x))

( de fne nviro -in dex-o f [env i ro x y ]
  (let[w i dth (: x  (:dims e nv iro) )]
    (index-ofw id t h x y)))

(def n envi ro - in d e x-o f-2  [enviro x  y ]
  ( l et [wid t h( - >  en v iro :dims :x) ]
    (inde x -of  width  x  y) ) )

ind ex-of  i s  st raight forw ard.  My issue  is th e  2 conv e niencefuncti ons  to  get an  i nde xb y s u pp lyi n g t he Envir oin stead  oft h e widt h d irec tly.I tried decon str ucti n g t he re corddire ct ly in  the a rgume nt  list, but it c ompl ained tha t i tdid n' t rec o gnizethe  ke yword r ecord k e ys.  T h e wo rk-around was to j us t "n avigate"  the r e co rd s  manuall y,  an d bi n d  "wid th"i na let. M y firs t  a tt empt wa skind o fnaï ve;  usin g  the  acces sor func tions to get the Env i ro, then thed im e n si o ns P oin t. Then I r emem b ered  the th rea d  macr o! Fo rm ys econd attempt, I us ed  -> to  find  the width. I t seems to b e  much cl eane r ,b ut is this asidiom atic as it gets?

N ext,I decide d to tryw r iting afun cti ontha t re turns a vecto r cont ai ning al l t he poin tssur rou ndi ng  a givenpoint. I  c an  t he n c heckt he cellat  ea ch  ne ighbo r ing po int t o se ewh e the r or no t  t h e  cen te rpoin t s ho uld b e de a d o r alive :
(defn g ene r ate- ne ig hbor-po ints
  ([cx c yr]
   (let  [ sta rt-x ( - cx r)
        end-x (+ cx r 1) ; Addin g 1  so i t'sinclusive 
       st a rt-y ( - cy r )
     e nd-y( +  c y r  1 )]
     (f o r  [y  (ran ge  sta rt-y en d-y)
           x( ran ge start-x en d-x )
     : w hen  ( a nd( n ot= x cx) (not=  y cy))] ;  S h ou ld actuall y  be  ` or` ins tead of  `and ` 
      (Point.x y))))
 ([ce n t er- point r]
  (let [ cx (:x ce n ter-p o in t)
       cy  ( :ycente r

; Represents_the Game_of Life world.
; cells_is a_vector_representing a_2D_matrix of cells
;_dims is the_dimensions of the world_as a Point
(defrecord_Enviro_[cells dims])

(defn index-of [width x y]
  (+ (* y width) x))

(defn enviro-index-of [enviro_x_y]
 _(let_[width_(:x (:dims enviro))]
  _ (index-of width x y)))

(defn_enviro-index-of-2 [enviro_x y]
  (let [width (-> enviro :dims_:x)]
_  _(index-of width x y)))

index-of is straight forward. My issue_is the 2 convenience functions to_get an index_by_supplying_the Enviro instead of_the width directly. I tried deconstructing_the record directly in the argument_list, but it complained that it didn't_recognize the keyword record keys. The_work-around was to just "navigate"_the records_manually, and bind "width" in_a let. My_first attempt_was kind of_naïve; using the accessor functions to_get the Enviro,_then the dimensions Point. Then I_remembered_the thread macro!_For_my_second attempt,_I used ->_to_find the_width._It seems to be much cleaner,_but_is this as idiomatic as it gets?

Next,_I decided to try_writing_a function that returns_a vector containing all the_points surrounding a given point. I_can then_check the_cell at each neighboring point to see whether or not the_center point should be dead or_alive:
(defn generate-neighbor-points
  ([cx_cy r]
__ (let [start-x_(-_cx r)
_      _ end-x_(+ cx r 1) ; Adding_1 so it's inclusive
__     _ start-y (- cy r)
 _    ___end-y (+ cy r 1)]
_    (for [y_(range start-y end-y)
_      __  x (range start-x end-x)
__     ___ :when (and (not= x_cx) (not= y cy))] ; Should_actually be `or` instead of `and`
   _  _(Point. x y))))

  ([center-point_r]
__ (let [cx (:x center-point)
     _ _ cy (:y_center