Question 6 of the example exam

8 views
Skip to first unread message

Maria Lemon Sjölander

unread,
Mar 15, 2011, 6:39:07 AM3/15/11
to proglang-course-2011
I can't read out from the solution pictures what the answer to that
question 6 is
since it is very blurry, did anyone write it down and can just write
the solution here?

vijay kumar

unread,
Mar 15, 2011, 6:42:49 AM3/15/11
to proglang-c...@googlegroups.com

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. 

Maria Lemon Sjölander

unread,
Mar 15, 2011, 10:20:36 AM3/15/11
to proglang-course-2011
Thank you!

On 15 mar, 11:42, vijay kumar <aphrovijay.s...@gmail.com> wrote:
> *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

MorF

unread,
Mar 15, 2011, 6:57:10 PM3/15/11
to proglang-course-2011
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.

But I believe the difference between c-b-n and c-b-v on lamda could be
only showed when considering Application.

Am I right? So It is basically question what should be written on the
exam then?




On Mar 15, 3:20 pm, Maria Lemon Sjölander <maria.lemo...@gmail.com>

Hamid Ebadi

unread,
Mar 15, 2011, 7:17:38 PM3/15/11
to proglang-c...@googlegroups.com


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


Termination of evaluation

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

Arnar Birgisson

unread,
Mar 15, 2011, 7:35:23 PM3/15/11
to proglang-c...@googlegroups.com, MorF
Hej,

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

Reply all
Reply to author
Forward
0 new messages