4.3BSD/usr/contrib/icon/book/f/filter2.icn

global A, B

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

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