이전 주제 보기 :: 다음 주제 보기 |
글쓴이 |
메시지 |
abebe
가입: 2023년 3월 15일 올린 글: 4
|
올려짐: 2023년4월21일 20:23 주제: [HW4] Question on Test Case #7 |
|
|
Dear TAs,
I have a question on the outcome of test case #7 below.
"
(* Public test case 7 : call by reference *)
let proc f (a,b,c) =
write a;
write b;
write c;
b := 5;
(a * b) + c
in
let x := 1 in
let y := 2 in
let z := 3 in
write(f <x,y,z> + y)
(* Output : prints out "1\n2\n3\n13\n" *)
"
Why is the output of "f <x,y,z> + y" 13? Shouldn't it be 10?
Thank you in advance for your response!
Dawit F. Amanu |
|
위로 |
|
|
김도형
가입: 2022년 3월 8일 올린 글: 103
|
올려짐: 2023년4월22일 14:34 주제: |
|
|
Hello.
As procedure f is called by reference, f gets the location for its variable.
Assigning a value 5 in 'b' actually involves assigning a value to its location, which is bound to variable y.
Hence, after f<x,y,z>, y's value should be changed.
Thank you. |
|
위로 |
|
|
|
|
새로운 주제를 올릴 수 없습니다 답글을 올릴 수 없습니다 주제를 수정할 수 없습니다 올린 글을 삭제할 수 없습니다 투표를 할 수 없습니다
|
Powered by phpBB 2.0.21-7 (Debian) © 2001, 2005 phpBB Group Translated by kss & drssay
|