Question: Include printlevel in procedure

Include print level in procedure
In the procedure code printlevel is not accepted
-enviroment variable
-interface variable 
error message : Error, (in interface) unknown interface variable, printlevel

More convenient in my opinion is to include on the printlevel depth in the procedure call?

restart;

fac := proc(n::integer)
    local previous_printlevel, result;
    previous_printlevel := interface('printlevel');  # Correct way to get the current printlevel
    interface('printlevel' = 3);  # Correct way to set the printlevel

    # De recursieve berekening
    if n = 0 then
        result := 1;  # Basisgeval
    else
        result := n * fac(n - 1);  # Recursieve aanroep
    end if;

    interface('printlevel' = previous_printlevel);  # Restore the original printlevel
    return result;
end proc;

fac(5);

proc (n::integer) local previous_printlevel, result; previous_printlevel := interface('printlevel'); interface('printlevel' = 3); if n = 0 then result := 1 else result := n*fac(n-1) end if; interface('printlevel' = previous_printlevel); return result end proc

 

Error, (in interface) unknown interface variable, printlevel

 
 

 

Download MP_vraag_printlevel_in_procedure_-lukt_niet.mw

Please Wait...