February 17, 2009

 

The development of FORTRAN. A story of innovation. The 25th Anniversary of FORTRAN video.

 

TEST on Thursday.

Test will be multiple choice and essay questions.

Sample questions

 

Press Spacebar to continue

SCOPE

When a language allows different variables to have the same name, it must have some way to ensure that each use of the name is unambiguous. This means there must be some way to control the  scope of definitions.

fun square n = n * n;
fun twotmes n = n + n;
	int main () {
    int n = 3;
    int m;
    m = n + 5;
    printf m;
    {
        int n = 6;
        m = n + 4;
        printf m;
    }
    printf m;
}
A definition is anything that establishes a possible binding for a name.

fun cube x =  x * x *x ;

fun cube cube = cube * cube * cube;

def cube( cube):
  

return cube * cube * cube;

 

 

Press Spacebar to continue

Static scope - definitions determined at compile time
Dynamic scope - definitions determined at run time.

1      program main;
2      var x: integer;
3      procedure Q(var i:integer; function R(j:integer):integer);
4              var x: integer;
5              begin
6                      x := 4;
7                      writeln('before call to R', i,x);
8                      i := R(i);
9                      writeln('after call to R',i,x);
10             end;
11     procedure P;
12             var i : integer;
13             function FN(k : integer):integer;
14                     begin
15                             x := x + k;
16                             FN := i + k;
17                             writeln('in FN',i,x);
18                     end;
19             begin
20                     i := 2;
21                     Q(x,FN);
22                     writeln('in P', i, x);
23             end;
24     begin
25             x :=  7;
26             p;
27             writeln('in main',x);
28     end.   
   

Press Spacebar to continue

Scoping with labeled namespaces


A labeled namespace is any language construct that contains definitions and a region of the program where those definitions apply, and also has a name that can be used to access those definitions from the outside.

IN ML
structure Fred = struct
    val a = 1;
    fun f x = x + a;
end;

outside can access Fred.a or Fred.f

class in java or C++ is another example. There we can mark items as public or private

 


Creative Commons License
This work is licensed under a Creative Commons License.
Ernest Ackermann Department of Computer Science, Mary Washington College
CPSC 110 | CPSC 330 | CPSC 401

Bibliographic Information: