Bounded Buffer Process

LA home
 FP,  λ
 Logic,  π


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
window on the wide world:

Computer Science Education Week

free op. sys.
free office suite,
ver 3.4+

~ free photoshop
web browser
like it says!

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

© L. Allison   (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, 01-Aug-2014 13:45:06 EST.