2.9. Procedures

Felix allows you to define procedures. They're like functions, but they can't return values. On the other hand, procedures may have side effects, and they may read input from the driver's message dispatch queue (which you will learn about much later).

Here is an example of a procedure definition and use:

Start felix section to tut/tutorial/tut-1.09-0.flx[1 /1 ]
     1: #line 464 "./lpsrc/flx_tutorial.pak"
     2: #import <flx.flxh>
     3: proc print_newline (a:int)
     4: {
     5:   print a;
     6:   print "\n";
     7: }
     8: print_newline 1;
End felix section to tut/tutorial/tut-1.09-0.flx[1]
Start data section to tut/tutorial/tut-1.09-0.expect[1 /1 ]
     1: 1
End data section to tut/tutorial/tut-1.09-0.expect[1]
There is a special shortcut for calling procedures with unit argument: if the procedure is called by its name, the () can be elided:
Start felix section to tut/tutorial/tut-1.09-1.flx[1 /1 ]
     1: #line 482 "./lpsrc/flx_tutorial.pak"
     2: #import <flx.flxh>
     3: print 1; endl();
     4: print 2; endl;
End felix section to tut/tutorial/tut-1.09-1.flx[1]
Start data section to tut/tutorial/tut-1.09-1.expect[1 /1 ]
     1: 1
     2: 2
End data section to tut/tutorial/tut-1.09-1.expect[1]
More precisely, a statement consisting of an (almost) atomic expression is taken to be a call to a procedure with unit argument. Note there is no confusion with the use of a procedure name as an expression, that always represents the closure of the procedure at the point of writing.


2.9.1. Preconditions and Postconditions