4.3BSD/usr/contrib/icon/book/13/filter1.icn

global A, B

procedure main()
   A := create compact("a", "b", create |reads(), B)
   B := create compact("b", "c", A, &main)
   repeat writes(@B)
end

procedure compact(s1, s2, in, out)
   local s
   repeat {
      s := @in
      if s == s1 then {
         s := @in
         if s == s1 then s := s2
         else s1 @ out
         }
      s @ out
      }
end