Fork me on GitHub
#beginners
<
2016-10-23
>
mruzekw07:10:57

I’m trying to render a simple 2D grid (with reagent) and I’m missing something:

(def app-state
  (r/atom
   {:board
    [nil nil nil]
    [nil nil nil]
    [nil nil nil]}))

;; UI components
(defn grid
  []
  [:div
   (for [row (:board @app-state)]
     [:div.row
        (for [col row]
           [:div.tile])])])

mruzekw07:10:24

Anyone see what I’m missing?

rackdon07:10:28

I think that the app state is wrong, maybe

{:board [ [nil nil nil]
               [nil nil nil]
               [nil nil nil] ]}

mruzekw07:10:56

Whoops, good catch. But that doens’t fix the issue

mruzekw07:10:36

It renders the rows but not the cols/tiles

rackdon07:10:09

really I don’t know where is the problem, I’m trying to make it works but I can’t…. 😔

rackdon08:10:57

@mruzekw I’ve solved it, but I don’t know why it doesn’t work with the other form…. (defn grid [] [:div (for [row (:board @app-state)] (`do` [:div.row (for [col row] [:div.tile])])]))

mruzekw08:10:52

Huh, thanks. I’ll investigate this further

mruzekw08:10:56

@rackdon I ended up using map-indexed instead

rackdon09:10:38

Ohhh I didn’t known this. Awesome!!!

kauko13:10:30

foris lazy. Wrapping it in doall will evaluate the sequence

kauko13:10:40

That's why it didn't work

mruzekw14:10:15

Ah makes sense

rackdon16:10:54

😅 you’re right…. thanks!!!

credulous21:10:18

Hey y’all. I’m confused about how to write a recursive function that continuously iterates a value… the way you would in an iterative numerical solution to a problem

credulous21:10:52

I’m doing an n-armed bandit, which means I’ve got functions that continually refine an array of n floats, which are the estimates of the values of n states

credulous21:10:28

This is what I have:

(defn run-experiment []
   (let [b (generate-bandit 10 0 1) ; The bandit, i.e. the true value function
         v (vec (repeat 10 0.0)) ; Our estimation of the value function
         p (partial epsilon-greedy-policy b 0.1)] ; Epsilon greedy
     (loop [values v]
       (let [return (p values)]
         (recur  (assoc values (first return) (second return)))))))

credulous21:10:50

generate-bandit just gives an array of 10 floats which are the true values (which I’m trying to iterate towards)

credulous21:10:52

epsilon-greedy-policy is a function that takes the bandit (true values), an epsilon value, and a vector, and applies an epsilon-greedy algorithm to the value array, returning which value was chosen and what the new updated value is

credulous21:10:17

The idea is that I’d like to (take 100 experiment) and get 100 iterations on the value array

credulous21:10:30

But this code isn’t lazy, and I don’t know how to make it lazy