在 clojure 中 - 如何一一使用列表元素?
我正在 Clojure 中使用 StructMap,并尝试通过值列表使用 struct 添加映射。 目前我的结构仅包含 3 个键,因此我使用以下内容来添加新结构:
(struct user-struct (first list-vals) (second list-vals) (nth list-vals 2))
但现在我想使用一个动态结构,用户将选择其中有多少个键。 因此需要使用某种循环来一一返回列表的元素。
有人知道我该怎么做吗?
谢谢。
i'm using a StructMap in Clojure, and trying to add map using struct by a list of values.
currently my struct includes only 3 keys, so i'm using the following to add new struct:
(struct user-struct (first list-vals) (second list-vals) (nth list-vals 2))
but now i want to use a dynamic struct which the user will choose how many keys will be in.
so in need to use some sort of loop which returns the list's element one by one.
does anybody has an idea how should i do it?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
注意:列表元素计数应与结构字段计数相同
NOTE: List elements count should be same as the struct fields count
根据http://clojure.org/data_struct,StructMap 的大多数用途现在可以通过记录更好地服务。
您应该尝试从结构图切换到记录。
According to http://clojure.org/data_structure, most uses of StructMaps would now be better served by records.
You should try to switch from structmap to record.