Previous Page Next Page Contents

%if -- conditional creation of code by the parser

Introduction

%if controls the creation of code by the parser depending on a condition.

Call(s)


%if condition
    then casetrue
     <elif condition then casetrue...>
     <else casefalse>
end_if

Parameters

condition - a Boolean expression
casetrue - a statement sequence
casefalse - a statement sequence

Related Functions

if

Details

Example 1

In the following example, we create debugging code in a procedure depending on the value of the global identifier DEBUG.

Note that this example is somewhat academic, as the function prog::trace is a much more elegant way to trace a procedure during debugging.

>> DEBUG := TRUE:
   p := proc(x) begin
        %if DEBUG = TRUE then
            print("entering p") 
        end;
        x^2
   end_proc:
   p(2)
                               "entering p"
       
                                     4

When we look at p, we see that only the print command was inserted by the parser:

>> expose(p)
                          proc(x)
                            name p;
                          begin
                            print("entering p");
                            x^2
                          end_proc

Now we set DEBUG to FALSE and parse the procedure again to create the release version. No debug output is printed:

>> DEBUG := FALSE:
   p := proc(x) begin
        %if DEBUG = TRUE then
            print("entering p")
        end;
        x^2
   end_proc:
   p(2)
                                     4

If we look at the procedure we see that NIL was inserted for the %if-statement:

>> expose(p)
                                 proc(x)
                                   name p;
                                 begin
                                   NIL;
                                   x^2
                                 end_proc

Background

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000