Prolog 中的惰性列表? [英] Lazy lists in Prolog?
问题描述
在 Prolog 中可以有惰性列表吗?类似于以下内容:
Is it possible to have lazy lists in Prolog? Something like the following:
ones([1 | Y]) :- ones(Y).
虽然这显然不像它写的那样工作.
Although this obviously doesn't work as it's written.
推荐答案
Markus Triska 放置在这里公开domain 一些代码值得研究:
Markus Triska placed here in public domain some code worth to study:
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Prolog stream/lazy list demonstration
Written 2005 by Markus Triska (triska@gmx.at)
Public domain code.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
文档的标题(prost,对于 Prolog 流)可能使文档成为有点难找,但很有道理.引用上面的:
The title of the document (prost, for Prolog streams) maybe make the document a bit difficult to find, but make sense. Quoting from the above:
这里的流"是指序列"、延迟列表"、计算机结构与解释中的懒惰列表"等程序,而不是 Prolog 输入/输出流的意义.
Here, "stream" is used in the sense of "sequence", "delayed list", "lazy list" etc. as in Structure and Interpretation of Computer Programs, not in the sense of a Prolog input/output stream.
这篇关于Prolog 中的惰性列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!