OEP

152

Title

ELSE case for tagged protocols

Summary

Allow a default action for all other tags in a tagged protocol

Owner

Damian Dimmich <damian@transterpreter.org>

Status

Proposed

Date-Proposed

2006-04-22

Keywords

channel comms protocol case

While using tagged protocols for channels is great, having to take into account all possible cases for when only a few are needed in a particular instance can be quite tedious. Often, the programmer only wants to provide specific behaviour for a subset of tags, just forwarding the others to another channel; currently they must write specific forwarding code for each of the cases. Allowing the programmer to simply write "for all other tags do X" would be convenient. For example:

PROC i.only.use.one.case (CHAN SOMEPROTO in?, out!)
  SEQ
    in ? CASE
      first; foo
        operate.on.foo (foo)
      ELSE tmp
        out ! tmp
:

The compiler could potentially expand that to handle all the tags automatically -- i.e. treat the ELSE block as a sort of "replicator over tags" -- although this is somewhat awkward when the communicated item isn't something that would usually fit in a single variable (such as a protocol containing two mobile or counted arrays, for example).

Another option would be to use a built-in procedure:

ELSE
  FORWARD (in?, out!)

or just specify the channel to forward to, although this would preclude doing other actions:

ELSE => out!

OEP/152 (last edited 2007-09-27 01:27:04 by ats1)