To assign a procedure to the identifier NAME, with formal identifiers FORMAL_IDFIER, ..., FORMAL_IDFIER, use the syntax
NAME := procedure([~]FORMAL_IDFIER, ..., [~]FORMAL_IDFIER) STATEMENTS end procedure;
If an identifier is prefixed with a ~ symbol, it is a reference identifier; otherwise it is a value identifier.
A call to this procedure is a statement of the form
NAME([~]ACTUAL, ..., [~]ACTUAL);
where the ACTUALs preceded by ~ are identifiers that correspond to the reference identifiers in the procedure definition, and the others are expressions that correspond to the formal value identifiers. The actual reference identifiers may be changed by what happens to their formal parallels.
When the procedure is called, during the execution of the STATEMENTS Magma may optionally encounter a statement of the form
return;
If so, execution of the procedure stops and execution returns to the place from which the procedure was called. Otherwise, if Magma does not encounter a return statement during runtime, then execution of the procedure call finishes at the end of the body of procedure statements.
Given a sequence Q of rational numbers and a Boolean b, this procedure removes from Q all the non-integral entries if b is true, and all the integral entries if b is false:> SelectIntegers := procedure(~Q, b) procedure> if b then procedure|if> Q := [Q[i]: i in [1..#Q] | IsIntegral(Q[i])]; procedure|if> return; procedure|if> end if; procedure> Q:=[Q[i]: i in [1..#Q] | not IsIntegral(Q[i])]; procedure> end procedure; > > r := [6/8, 3, -8/4, 7, 36/5]; > SelectIntegers(~r, true); > print r; [ 3, -2, 7 ]