将排序向量中的前五十项放入另一个向量中(clojure)
已编辑,因为问题是关于同一个程序的。
我试图获取第一个向量中的前 50 个项目并将它们写入 topfifty 变量,以返回在其他地方使用。
"gets the closest 50 locations in the file fName and writes them out by sending a function to the agent"
[fName]
(let [sorted (sort-by sortFn (makeStructs fName))
topFifty ;TODO take the top 50 from sorted
]
我到底如何在 Clojure 中做到这一点?我是这门语言的新手,从未使用过 lisp。我宁愿不使用 for 循环,因为这不完全是函数式的。
EDITED because question is about same program.
I'm trying to take the top fifty items in the first vector and write them to the topfifty variable, to return to use elsewhere.
"gets the closest 50 locations in the file fName and writes them out by sending a function to the agent"
[fName]
(let [sorted (sort-by sortFn (makeStructs fName))
topFifty ;TODO take the top 50 from sorted
]
How exactly do I do this in clojure? I'm new to the language and have never used lisp. I'd rather not use a for loop as that is not exactly functional-ish.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要回答新问题(我的其他答案所回答的问题已被替换):
(take 50 returned)
将返回sorted
的前 50 个元素。To answer the new question (the question that my other answer was in response to has been replaced):
(take 50 sorted)
will return the first 50 elements ofsorted
.您可能需要类似
(apply struct storeinfo vals)
的内容,其中vals
是拆分的结果。这会将vals
中的所有值解压到对(struct storeinfo ...)
的调用中,这会根据 中的初始值创建一个storeinfo
与其定义的顺序相同。You probably want something like
(apply struct storeinfo vals)
, wherevals
is the result of your split. This unpacks all of the values invals
into a call to(struct storeinfo ...)
, which creates astoreinfo
from initial values in the same order as its definition.