Prolog中的惰性列表? [英] Lazy lists in Prolog?

查看:24
本文介绍了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 placed here in public域一些代码值得学习:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆