function nand(name x,y:boolean):boolean; begin if not x then nand := true else if not y then nand := true else nand := false end;In C-like (using the fact that || is non-strict):
int nand(name int x,y){ return (!x)||(!y); }
function sum_list(l:list):integer; begin if isempty(l) then sum_list := 0 else sum_list := head(l) + sum_list(tail(l)) end;In C:
int sum_list(list l){ if (isempty(l)) return 0; else return head(l) + sum_list(tail(l)); }
caller of p p I A.R. where p is declared ^ ------------------ ^ CL |___|_ | | | | | ------------------ | | _|______| SL | | ------------------ |-->| ----- |<-|---|----| | | x | 1 | | | | | | | ----- | | | | | | y | 2 | | | | | | | ----- | | | | CL | ------------------ | | | | | | | | q I | | | | ------------------ | | | |___|_ | | | | | | | | | ------------------ | | | | _|__|SL | | | | | | ------------------ | | |-->| ----- | | | | | y | 1 | | | | | | ----- | | | CL | ------------------ | | | | | | r I | | | ------------------ | | |___|_ | | | | | | | ------------------ | | | _|______| SL | | | | ------------------ | |-->| ----- | | | | x | 2 | | | | | ----- | | CL | ------------------ | | | | Q II | | ------------------ | |___|_ | | | | | ------------------ | | _|___________| SL | | ------------------ | ----- | | y | 2 | | | ----- | ------------------ CL = Control Link SL = Static Link
foo1(){ int *q; q = new int; *q = 5; p = q; delete(q); } foo2(){ int *r; r = new int; *r = 6; delete(r); }
foo1(){ int x; x = 5; p = &x; } foo2(){ int y; y = 6; }
Another way in which foo2 can change the value of *p is by using pointer arithmetic: foo2 might assign to a local pointer exactly the location pointed by p and then change its value.