RosettaCodeData/Task/Odd-word-problem/Zkl/odd-word-problem-1.zkl
2017-09-25 22:28:19 +02:00

15 lines
566 B
Text

var [const] delim=",:;/?!@#$%^&*()_+", stop=".";
fcn oddly(inStream){
inStream=inStream.walker(3); // character iterator: string, file, etc
doWord:=fcn(inStream,rev,f){ // print next word forewards or reverse
c:=inStream.next();
if(not rev) c.print();
if(not (c==stop or delim.holds(c)))
return(self.fcn(inStream,rev,'{ c.print(); f(); }));
if(rev){ f(); c.print(); }
return(c!=stop);
};
tf:=Walker.cycle(False,True); // every other word printed backwords
while(doWord(inStream, tf.next(), Void)) {}
println();
}