December 4th Friday 2009

In Erlang,  the both syntax of Bit String Comprehensions and List Comprehensions are so similar.

 

Bit string comprehensions are written with the following syntax:

<< BitString || Qualifier1,...,QualifierN >>

BitString is a bit string expression, and each Qualifier is either a generator, a bit string generator or a filter.

 

List comprehensions are written with the following syntax:

[Expr || Qualifier1,...,QualifierN]

Expr is an arbitrary expression, and each Qualifier is either a generator or a filter.

 

  From their aspects, there is only difference at the brackets.  Yes, a bit string comprehension returns a bit string, which is created by concatenating the results of evaluating BitString for each combination of bit string generator elements for which all filters are true. A list comprehension returns a list, where the elements are the result of evaluating Expr for each combination of generator list elements and bit string generator elements for which all filters are true.

 

A generator is written as:
  Pattern <- ListExpr.
ListExpr must be an expression which evaluates to a list of terms.
A bit string generator is written as:
  BitstringPattern <= BitStringExpr.
BitStringExpr must be an expression which evaluates to a bitstring.
A filter is an expression which evaluates to true or false.
The variables in the generator patterns shadow variables in the function clause surrounding the bit string comprehensions.

 

  That is so nature to our mind.  It is easy to remember them.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值