4. Scope
Unlike C++, the scope of an identifier is the
whole of the construction containing it, just
like labels. In particular, all functions in
the same scope are mutually recursive: a function
can be called before it is defined without a
forward declaration.
Start felix section to tut/migration//mig-4-0.flx[1
/1
]
1: #line 203 "./lpsrc/flx_tut_migrate.pak"
2:
3: fun f(x:int) => g(x-1);
4: fun g(x:int) => if x>0 then f(x-1) else 0 endif;
5: print (g 10); endl;
Start data section to tut/migration//mig-4-0.expect[1
/1
]
In particular this rule also applies to types,
allowing recursive types to be easily defined:
Start felix section to tut/migration//mig-4-1.flx[1
/1
]
1: #line 217 "./lpsrc/flx_tut_migrate.pak"
2:
3: union ilist = empty | cons of int * ilist;
4: var x = empty;
5: x = cons (1,x);
6: x = cons (2,x);
7:
8: proc xprint(x:ilist) {
9: match x with
10: | empty => {}
11: | cons (?h,?t) => { print h; print " "; xprint t; }
12: endmatch;
13: }
14:
15: xprint x; endl;
Start data section to tut/migration//mig-4-1.expect[1
/1
]