“应用” 和 “应用” 和有什么不一样?和“mapcar”在 Lisp 中
(defun describe-paths (location edges)
(apply #'append (mapcar #'describe-path (cdr (assoc location edges)))))
(defun describe-paths (location edges)
(apply #'append (mapcar #'describe-path (cdr (assoc location edges)))))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有哪些相似之处?或者,这里还潜藏着另一个问题吗?
是我所知道的。引用只是摘录,链接包含可能与特定“Lisp”相关或不相关的示例。)
(来自 elisp 的链接,因为这 org/software/emacs/emacs-lisp-intro/html_node/mapcar.html">mapcar
应用(在调用函数中)
快乐编码。
What are the similarities? Or, is there another question lurking here?
(Links from elisp, because that is what I know. The quotes are just excerpts and the links contain examples which may or may not be relevant in a particular "Lisp".)
mapcar
apply (in Calling Functions)
Happy coding.
describe-paths
函数(来自 Land of Lisp 中基于文本的冒险游戏!) 生成从给定位置出发的路径的描述。 Land of Lisp 中的第 74-77 页解释了示例中mapcar
和append
的作用。(cdr (assoc location Edges))
提供从该位置出发的所有路径的列表,例如living-room
位置的路径:mapcar
调用该函数每个的describe-path
路径,将路径描述收集到一个列表中,其中每个子列表都是一个路径描述:接下来,append 函数应用于路径描述列表,将其连接成一个平面列表:
The
describe-paths
function (from the text based adventure game in Land of Lisp!) generates descriptions for the paths going from a given location. Page 74-77 in Land of Lisp explains the roles ofmapcar
andappend
in the example.The
(cdr (assoc location edges))
provides a list of all paths going from the location, such as these for theliving-room
location:The
mapcar
calls the functiondescribe-path
for each of the paths, collecting the path descriptions into a list where each of the sublists is a path description:Next the
append
function is applied to the list of path descriptions, concatenating it into a flat list: