OEP

168

Title

New FUNCTION syntax, and removing VALOF

Summary

Remove VALOF in favour of a simplified syntax for FUNCTIONs

Owner

Adam Sampson <ats@offog.org>

Status

Proposed

Date-Proposed

2008-02-05

Keywords

language syntax function valof

The original occam language defined functions in terms of VALOF, which could be used anywhere in an expression to insert a process (provided it had no side-effects). Inline VALOF is awkward to parse, though, since it breaks occam's usual indentation rules, and a discussion on occam-com suggested that it was not widely used (if at all).

(The argument in favour of VALOF is that it provides an elegant way of defining the semantics of FUNCTIONs -- as simple textual expansion -- but that's broken already for functions with multiple return values.)

Meanwhile, the syntax for FUNCTIONs is rather clumsy, particularly for functions that are very short but not quite short enough to use the FUNCTION ... IS syntax:

INT FUNCTION simple (VAL INT x)
  VALOF
    SKIP
    RESULT (x * 42) + very.long.name (x, 1234)
:
INT, INT FUNCTION product.range (VAL INT x, y)
  INITIAL INT n IS 1:
  VALOF
    SEQ i = x FOR y
      n := n * i
    RESULT n, x + y
:

This OEP's proposal is to remove both inline and function VALOF, and implement a more Pascal-like syntax for functions in which assignment to the function name sets the return values. The above example could then be written as:

INT FUNCTION simple (VAL INT x)
  simple := (x * 42) + very.long.name (x, 1234)
:
INT, INT FUNCTION product.range (VAL INT x, y)
  INITIAL INT n IS 1:
  SEQ
    SEQ i = x FOR y
      n := n * i
    product.range := n, x + y
:

The short function becomes two lines shorter; the long function stays the same length, but uses common keywords rather than requiring the VALOF ... RESULT construct.

The compiler should enforce that each function contains exactly one assignment to the function name. Reading from the function name would be prohibited -- it wouldn't actually be a variable.

OEP/168 (last edited 2008-02-05 15:56:52 by ats)