Erlang列表操做里面的变量绑定规则

原文以下: spa

The scope rules for variables which occur in list comprehensions are as follows: 翻译

  • all variables which occur in a generator pattern are assumed to be "fresh" variables
  • any variables which are defined before the list comprehension and which are used in filters have the values they had before the list comprehension
  • no variables may be exported from a list comprehension.

译文: 作用域

    列表操做里面的变量的做用域遵循如下原则: generator

    。全部出如今发生器里面的变量都被假设为“新”变量(也就是未经绑定的变量)。 io

    。全部定义在列表操做以前的变量,即便在列表过滤条件中使用,也仍然会保存以前绑定的值。(跟第一条是同样的么,虽然名字相同,实际上是一个“新”变量) 变量

    。全部列表操做里面使用的变量都不会被导出,也就是说,列表操做里面的变量做用域仅在列表操做里面, sed

PS:list comprehension实在是不知道怎么翻译,因此翻译成了“列表操做”,有人知道怎么翻译能够给我留言。 im

例子: filter

    

相关文章
相关标签/搜索