I’m trying to display the items in the menu-items variable using the for-macro:
(defrecord MenuItem
[select-char description])
(def menu-items [(MenuItem. "1" "add an expense")
(MenuItem. "2" "add an income")
(MenuItem. "0" "exit")])
(defn display-menu [items]
(for [item items]
(println (:select-char item))))
(defn menu-prompt [items]
(display-menu items)
(read-val ">>>"))
(println menu-items)
(menu-prompt menu-items)
However, nothing but the >>> prompt is displayed. Could someone explain why that is, and how to display the items?
this is a case of “the lazy bug”
for produces a lazy sequence that is only evaluated as it is read.
the call to display-menu just returns a reference to the list and then
goes on it’s marry way having done nothing.
wrap it in a call to
doallif you use doall or dorun then it will do the work immediately.