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

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

问题描述

我一直在阅读Erlang和OTP的行动,并绊倒了一个关于不当列表的问题。

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


不要试图以这种方式使用列表单元格
即使你认为你有一个
聪明的想法 - 这是错误的,
混淆了人类和程序
分析工具。也就是说,
有一个或两个有效用途来创建
不正确的列表,但它们被认为是
高级编程技术,
超出了本书的范围。 p>

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天全站免登陆