Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
notes11
[go: Go Back, main page]

DAT2 - SPO - Spring 2002

Lecture 11

 

Subjects:

Procedures and functions 1.

 

 

Readings:

Sehti, chap. 5, until p. 171

 

 

Notes:

Procedures and functions

"Yeah, but we do know what that is!"

Well, of course you do, but anyhow, there might be some details you would find interesting. For instance, there is a variety of methods to pass parameter to procedures or functions: call-by-value, call-by-reference, call-by-value-result and call-by-name.

Another interesting topic is dynamic scope. The opposite, static scope, is used in most languages nowadays, but actually its much easier to implement dynamic scope. But the problem is, that it is much harder for humans to understand what programs under static scope are doing. And likewise it is much harder for a compiler to figure out what programs are trying to do, and hence it is much more difficult to use static type checking.

Towards the end we will discuss nested scopes. This concept is useful in understanding inner classes in Java (and C++) and of course languages, which use nested scopes (Pascal, SML, Haskell and others). 

 

 

Exercises:

  program
	  var x: Integer;
	  procedure foo(name y: Integer);
	    var i: Integer
	  begin
	    for i:=1 to 3 do writeln(y);
	  end;
	  function inc(var z: Integer): Integer;
	  begin
	    z := z+1;
	    inc := z;
	  end
  begin
	  x := 0;
	  foo(inc(x));
  end.