# Derived from `The Icon Programming Language', (1st edn, Ch13 s13.4.2 p139) # # coexpressions: create, @ # # A: replace aa by b B: replace bb by c # reads---->A-------------------------->B-------------->writes # aa... -> b... | |bb... -> |c... # ax... -> ax...|----------->|bz... -> |bz... # x... -> x... | |x... -> |x... global A, B procedure main() A := create compact("a", "b", create |reads(), B) # coexpression A # s1 s2 ------in------- out B := create compact("b", "c", A, &main) # coexpression B # s1 s2 in -out- write("type input lines, try single and multiple a's and b's") while writes(@B) end procedure compact(s1, s2, in, out) # compact two s1's into an s2 local s while s := @in do { if s == s1 then { s := @in if s == s1 then # -> s := s2 else s1 @ out # <~s1> -> <~s1> } s @ out } end #\fB Example of Coexpressions. \fP