Scala-Evaluation Strategies and Termination (4_22)
2015-03-11 16:00
267 查看
This scheme of expression evaluation is called substitution model.将一个表达式计算为一个数值。对没有side effects的表达式都可以使用。
Side effect:
例:
def test(x:Int, y:Int) = x*x
test(3+4, 8)
Call-by-value
test(7,8)->7*7->49
Call-by-name
Test(7,8)->(3+4)*(3+4)->7*(3+4)->7*7->49
CBV evaluation of an expression e terminates, then CBN evaluation of e terminates, too. The other direction is not true.
Scala choose CBV. If you want to use the CBN, you can use the => to tell it like def constOne(x:Int, y:=>Int)=1
如果CBV能终止 那么CBN一定能终止 反过来不成立
例子:
def first(x:Int , y:Int) =x
def loop()=loop
first(1,loop)
那么CBN一定可以终止的 CBV不会,CBV会在loop造成循环。
Side effect:
Call-by-name
has the advantage that a function argument is not evaluated if the corresponding parameter is unused in the evaluation of the function body.Call-by-value
has the advantage that it evaluates every function argument only once.例:
def test(x:Int, y:Int) = x*x
test(3+4, 8)
Call-by-value
test(7,8)->7*7->49
Call-by-name
Test(7,8)->(3+4)*(3+4)->7*(3+4)->7*7->49
CBV evaluation of an expression e terminates, then CBN evaluation of e terminates, too. The other direction is not true.
Scala choose CBV. If you want to use the CBN, you can use the => to tell it like def constOne(x:Int, y:=>Int)=1
如果CBV能终止 那么CBN一定能终止 反过来不成立
例子:
def first(x:Int , y:Int) =x
def loop()=loop
first(1,loop)
那么CBN一定可以终止的 CBV不会,CBV会在loop造成循环。
相关文章推荐
- Actors in Scala(Scala中的Actor)(预打印版) 第六章 Exception Handling, Actor Termination and Shutdown(A)
- Scala-3 - 7 - Lecture 2.7 - Evaluation and Operators (16_25)
- Scala and Evaluation Strategy
- CS231n Neural Networks Part 3: Learning and Evaluation Babysitting the learning process
- SAMATE - Software Assurance Metrics And Tool Evaluation
- 【转载】M2K (Music-to-Knowledge): A tool set for MIR/MDL development and evaluation
- scala sortBy and sortWith
- SDP(9):MongoDB-Scala - data access and modeling
- scala22-Scala中的闭包
- 快学Scala学习笔记及习题解答(21-22隐式转换和隐式参数、定界延续)
- LeetCode with C++ and Java and little Scala (持续更新)
- Applied SOA: Service-Oriented Architecture and Design Strategies
- Scala:Functions and Closures
- Scala program build and run
- Chapter 22: Using Item Renderers and Item Editors--Creating inline item renderers and editors
- Step into Scala - 22 - Xml
- 【转】The Architecture Twitter Uses To Deal With 150M Active Users, 300K QPS, A 22 MB/S Firehose, And Send Tweets In Under 5 Second
- 22 free tools for data visualization and analysis
- How to Install PostgreSQL 9.5 on CentOS/RHEL 7/6/5 and Fedora 23/22
- SDP(9):MongoDB-Scala - data access and modeling