现在的位置: 首页 > 综合 > 正文

November 12th Thursday

2013年11月27日 ⁄ 综合 ⁄ 共 668字 ⁄ 字号 评论关闭

  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.

抱歉!评论已关闭.