Call by value (as above): evaluate argument before substitution
env => fun ⇩ (\x -> body) env => arg ⇩ val env => body(val/x) ⇩ result ---------------------------------------------------------------------------- env => (fun arg) ⇩ result
Call by name : substitute first, then evaluate
env => fun ⇩ (\x -> body) env => body(arg/x) ⇩ result -------------------------------------------------------- env => (fun arg) ⇩ result
The above is from the Lecture 10
and the evaluation strategy is clear in the picture.
I think it is enough to write its big-step semantics , following lines are just copied from the lecture 10 :
http://www.cse.chalmers.se/edu/course/TIN321/lectures/proglang-10.html
Two evaluation strategies.
Call by value (as above): evaluate argument before substitution
env => fun ⇩ (\x -> body) env => arg ⇩ val env => body(val/x) ⇩ result
----------------------------------------------------------------------------
env => (fun arg) ⇩ result
Call by name : substitute first, then evaluate
env => fun ⇩ (\x -> body) env => body(arg/x) ⇩ result
--------------------------------------------------------
env => (fun arg) ⇩ result
Consider the code
infinite = 1 + infinite
first x y = x
main = first 5 infinite
With call by value, we get
main
= first 5 infinite
= (\x -> \y -> x) 5 (1 + infinite)
= (\y -> 5) (1 + infinite)
= (\y -> 5) (2 + infinite)
...
With call by name,
main
= first 5 infinite
= (\x -> \y -> x) 5 infinite
= (\y -> 5) infinite
= 5
On Tue, Mar 15, 2011 at 23:57, MorF <nuz...@gmail.com> wrote:
> BTW I may join the topic
> If there is a question (taken from exam 2008-0.pdf)
>
> "6. Write operational semantic rules showing the difference between
> call-by-value
> and call-by-name lambda calculus. Also give an example of an
> expression that
> behaves differently in these two kinds of semantics. (10p)"
>
> All we can write for both call-by-name and call-by-value is
> env => (\x -> body) ⇩ (\x -> body)
>
> Since Lambda evaluates to itself.
Lambda abstractions are already values, so they do not need any evaluation.
> But I believe the difference between c-b-n and c-b-v on lamda could be
> only showed when considering Application.
Indeed.
> Am I right? So It is basically question what should be written on the
> exam then?
Hamid already answered this one :)
cheers,
Arnar