Bounded Buffer Process

home1 home2
 Bib
 Algorithms
 Bioinfo
 FP
 Logic
 MML
 Prog.Lang
and the
 Book

FP
 PFL
  Examples
  Syntax

The bounded buffer function, bbuffer, takes as parameters a bound, an input channel, inch, and an output channel, opch, and produces a buffer process. The buffer process sits between the input and output channels and smooths out variations in production and consumption rates in the usual way. When the buffer is empty (size=0) it will only accept from the input channel an item (inch?x) to be stored. When the buffer is full (size=bound) it will only offer to pass on to the output channel (opch!hd buff) the oldest item in the buffer. When the buffer process is neither full nor empty it will either accept another item or ("|") pass one on.

bbuffer = lambda bound. lambda inch. lambda opch.
  let rec
    add = lambda x. lambda L. {add element x to list L}
      if null L then x::nil else (hd L)::(add x (tl L)),

    bb = lambda size. lambda buff.
      if size=0 then                           {empty}
        inch?x       -> bb 1 (x::nil)
      else if size=bound then                   {full}
        opch!hd buff -> bb (size-1) (tl buff)
      else                    {neither full nor empty}
        opch!hd buff -> bb (size-1) (tl buff)   |
        inch?x       -> bb (size+1) (add x buff)

  in  bb 0 nil

{\fB Bounded Buffer. (incomplete program) \fP}

e.g. c1993
Coding Ockham's Razor, L. Allison, Springer

A Practical Introduction to Denotational Semantics, L. Allison, CUP

Linux
 Ubuntu
free op. sys.
OpenOffice
free office suite
The GIMP
~ free photoshop
Firefox
web browser

pfl...
|   choice
|| parallel
-> sequence
? input act
! output act
chan new channel

© L. Allison   http://www.allisons.org/ll/   (or as otherwise indicated),
Faculty of Information Technology (Clayton), Monash University, Australia 3800 (6/'05 was School of Computer Science and Software Engineering, Fac. Info. Tech., Monash University,
was Department of Computer Science, Fac. Comp. & Info. Tech., '89 was Department of Computer Science, Fac. Sci., '68-'71 was Department of Information Science, Fac. Sci.)
Created with "vi (Linux + Solaris)",  charset=iso-8859-1,  fetched Friday, 29-Mar-2024 13:33:27 AEDT.