1: #line 404 "./lpsrc/flx_tut_macro.pak"
2:
3:
4: macro proc k ()
5: {
6: val yy = xx * xx;
7: print xx; print " -> "; print yy; endl;
8: }
9:
10: {
11: val xx = 1;
12: k();
13: };
14: {
15: val xx = 2;
16: k();
17: };
18:
19: macro proc pkg (x)
20: {
21: macro proc printxy (y) { print (x+y); endl; }
22: macro val doublex = x + x;
23: }
24:
25: pkg 10;
26: printxy doublex;
27:
28: macro proc dump_s (sts:proc)
29: {
30: print "Start dump_s"; endl;
31: sts;
32: print "End dump_s"; endl;
33: }
34:
35: macro proc dump_e (sts:fun)
36: {
37: print "Start dump_e"; endl;
38: sts;
39: print "End dump_e"; endl;
40: }
41:
42: dump_s { print 1; endl; print 2; endl; };
43: dump_e { val x = 1; print x; endl; print 2; endl; };
44:
45: macro proc todump () { print "Dumped"; endl; }
46: dump_s todump;
47: dump_e todump;
48:
49: macro proc todump_wa (x) { print x; endl; }
50: dump_s (todump_wa 66);
51: dump_e (todump_wa 66);
52:
Note there is a crucial difference between procedure
and expressions macros. In the above example,
dump requires a proc argument. When the parameter
is expanded, the list of statements it represented
is produced. Had this been a function macro,
the result would have been an the call executable lambda
expression applied to unit argument. The difference
is in the handling of any variable declarations:
they'd be exposed in the first case, but not the second.