OEP

106

Title

Recursive PROCs

Summary

Add RECURSIVE/REC keyword to allow a PROC to call itself.

Owner

Fred Barnes <F.R.M.Barnes@kent.ac.uk>

Status

Accepted

Date-Accepted

2001-11-30

Keywords

language recursion procs

On the theme of dynamic occam, recursion has now been implemented. This is still fairly basic and there are several restrictions:

Recursive PROCs are declared by adding the "RECURSIVE" or "REC" keyword to the procedure header. Here is an example:

REC PROC thing (VAL INT c, CHAN BYTE out!)
  SEQ
    out.string ("Hello world at ", 0, out!)
    out.int (c, 0, out!)
    out ! '*n'
    IF
      c = 0
        SKIP
      TRUE
        thing (c - 1, out!)
:

This example is actually slightly silly, since we could do tail-call optimisation, thus removing the recursion. This optimisation has not been implemented yet however.

OEP/106 (last edited 2007-09-27 00:06:19 by ats1)