Go to the Next or Previous section, the Detailed Contents, or the FS(E)L Home Page.


4.2.3 Use local definitions

When constructing processes, the use of local definitions allows us to separate out those arguments which are passed in for configuration purposes (sizes, channels and so on) from those which represent process state and may need to modified on recursive calls. For example, in FDR1 we might have written

N = 6

BUFF(s) =
  not null(s) & out!head(s)->BUFF(tail(s))
[]
  #s<N & in?x->BUFF(s^<x>)

which `wires-in' to the definition the name (and so type) of the channels along with the buffer size. It also requires users to know that the buffer must be given an initial argument of the empty sequence. With local definitons we can write

BUFF(N,in,out) = -- configuration arguments
  let
    B(s) = -- process state
      not null(s) & out!head(s) -> B(tail(s))
    []
      #s < N & in?x -> B(s^<x>)
  within B(<>) -- initialisation of process state

which generalises the definition so it can be used with different channels and sizes and also conceals the need for an initial argument.


Go to the Next or Previous section, the Detailed Contents, or the FS(E)L Home Page.