【发布时间】:2015-01-10 16:16:07
【问题描述】:
我目前正在学习 Clojure,但我很难进入函数式思维模式。
我有一张试图从命令行填充的地图。这是我到目前为止的代码:
(ns dungeonworld.core
(:gen-class))
(def pc {:Name ""
:Class ""
:Race ""
:Look ""
:Str 0
:Dex 0
:Con 0
:Wis 0
:Int 0
:Cha 0
})
(defn getVals
[]
(println "Enter Name: ")
(assoc pc :Name (read-line))
(println "Enter Class: ")
(assoc pc :Race (read-line))
(println "Enter Look: ")
(assoc pc :Look (read-line)))
(defn -main
"Create a Dungeon World character map"
[& args]
(getVals))
但是它只更新最后一个条目 (:Look)。
问题: 我如何以更实用的 Clojure-y 方式实现我想要实现的目标,为什么它只更新最后一个地图元素?地图类型合适吗?
非常感谢!
【问题讨论】: