# # Rot13.pli # module "/pliant/language/unsafe.pli" module "/pliant/language/os.pli" # define types type MajLetter field Char c type MinLetter field Char c type Character field Char c Character maybe MajLetter Character maybe MinLetter # define generic methods method x Rot13 arg_rw Character x generic method x Rot13 arg_rw MajLetter x generic x:c := character "A":number+((x:c:number-"A":number) + 13)%26 method x Rot13 arg_rw MinLetter x generic x:c := character "a":number+((x:c:number-"a":number) + 13)%26 # a function to convert a Char into the appropriate Character sub-type function Precise c -> w arg Char c; arg Link:Character w if (c>="A" and c<="Z") w :> new MajLetter eif (c>="a" and c<="z") w :> new MinLetter else w :> new Character w:c := c # The method Rot13 for a Char : precise and Rot13 on the Character method c Rot13 -> cc arg Char c cc var Link:Character w :> Precise c w:Rot13 cc := w:c # Perform read/transform/write using OS read and write gvar Char c cc # c and cc are global Char variables while (os_read 0 addressof:c 1)=1 cc := c Rot13 os_write 1 (addressof cc) 1