[Oberon] CAP and recursion

John Stout jstout at cusp.co.uk
Mon May 22 23:52:45 CEST 2006

> I want to understand the "built in" functions (if that is the correct
terminology) better.
> CAP( ) for example. Appears it is defined in OPB.Mod. Ie.
> | cap:
> IF f = Char THEN
> 	IF z^.class = Nconst THEN
> 	z^.conval^.intval := ORD(CAP(CHR(z^.conval^.intval)));
> 	z^.obj := NIL
> ELSE z := NewOp(op, typ, z)
> ELSE err(111); z^.typ := OPT.chartyp
> Can anyone shed a little light on this?
> With ORD(CAP(CHR(z^.conval^.intval)))
> present, how is this not a recursive definition?

This is NOT a recursive definition. It would only be a recursive definition
if the procedure within which it is called is called CAP and had the same
signature, i.e., CAP(CHAR):CHAR.

It isn't: it's inside a procedure called MOp*(SHORTINT;VAR OPT.Node); so
that there is no recursion at all, even indirectly. I think you are
confusing the code that is being generated by the compiler when it compiles
CAP(variable) and the code that is executing when the compiler compiles

There is no code generated when CAP(constant) is compiled: the integer
representation of the character being converted is replaced by the integer
representation of the CAP of the character being replaced in the code-tree
being created. The CHR is necessary to tell the compiler that CAP is
receiving a CHAR and not an INTEGER (.intval) and the ORD 'converts' back
the CHAR that CAP returns to the INTEGER form (.intval).

John Stout

No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.392 / Virus Database: 268.6.1/343 - Release Date: 18/05/2006

More information about the Oberon mailing list