Erlang 中不正确列表的实际使用(可能所有函数式语言) [英] Practical use of improper lists in Erlang (perhaps all functional languages)

查看:13
本文介绍了Erlang 中不正确列表的实际使用(可能所有函数式语言)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读Erlang 和 OTP in action,并偶然发现了一个关于不正确列表的问题.

I've been reading Erlang and OTP in action, and stumbled upon a question with regards to improper lists.

不要试图使用列表单元格这样即使你认为你有聪明的想法 - 它容易出错并且混淆人类和程序分析工具.也就是说,有用于创建的一两个有效用途不正确的列表,但它们被认为是先进的编程技术和超出了本书的范围.

Don’t be tempted to use list cells this way even if you think you have a clever idea — it’s bug-prone and confuses both humans and program analysis tools. That said, there are one or two valid uses for creating improper lists, but they’re considered advanced programming techniques and are beyond the scope of this book.

超出本书的范围?它必须非常适合 Stackoverflow!
所以我的问题当然是,一些有效的用途是什么?

Out of scope for the book? It must be perfect for Stackoverflow!
So my question is, of course, what would some valid uses would be?

推荐答案

Erlang 文档建议的一种用法是 伪造懒惰列表:

One use suggested by Erlang documentation is faking lazy lists:

-module(lazy).
-export([ints_from/1]).
ints_from(N) ->
    fun() ->
            [N|ints_from(N+1)]
    end.

这篇关于Erlang 中不正确列表的实际使用(可能所有函数式语言)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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