next up previous
Next: About this document ... Up: Tips and Tricks Previous: Tips and Tricks

Side Effects

Some external function calls have side effects and return type ``.'' (such as print or many of the windows functions). You might want to write a function that draws a picture involving several windows calls. One way to do this is, for example,

fun draw w . 
  { line ( w, -1, 0, 1, 0 ), 
    line ( w, 0, -1, 0, 1 ) };
which draws a crosshairs in the window w. It's return type is unit list, which you can just throw out. What if you want the function to return a value or the functions you want to call don't all return unit? Then, put the commands in a let expression, as in
fun draw w . 
  let dummy := { line ( w, -1, 0, 1, 0 ), 
                 line ( w, 0, -1, 0, 1 ) } in
    true
  end;
which returns true (and could have any expression you want for the body of the let expression). You would have multiple definitions in the let statement for functions return other types.



Eric Klavins 2003-12-03