November 12th Thursday

  In Erlang, there is a interesting syntax to make a list, it is called List Comprehensions.  Let's call up some mathematical expressions in our middle school, such as { X | X > 0}.  The List Comprehension likes that.  It can be expressed obviously, naturally, and easy to be understood.

 

  I have sawn the syntax in prolog firstly.  Erlang has also it.  Let's look an example.

 

L = [1, 2, 3, 4, 5].

[2 * X || X <- L].

 

=> [2, 4, 6, 8, 10]

 

  Oh.  That is just the range expression.  When we are young, we have known that.  Maybe the next generation will learn functional programming in the future.  That is a natural way to write a program.

 

  Yes.  You can make a list in another way.  But if you use the syntax, you can get benefit from the Erlang becaus the syntax will deal with the logic of making a list optimistically.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值