[q-lang-cvs] q/stdlib prelude.q,1.19,1.20
Brought to you by:
agraef
From: Albert G. <ag...@us...> - 2006-06-09 11:20:09
|
Update of /cvsroot/q-lang/q/stdlib In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv31575 Modified Files: prelude.q Log Message: overhaul of enumeration operations Index: prelude.q =================================================================== RCS file: /cvsroot/q-lang/q/stdlib/prelude.q,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** prelude.q 9 Jun 2006 04:15:41 -0000 1.19 --- prelude.q 9 Jun 2006 11:20:04 -0000 1.20 *************** *** 133,137 **** [X:Num,Y:Num..Z:Num] = numsby (Y-X) X Z; ! /* Enumeration operations for streams. */ {X:Num..} = numstream X; --- 133,145 ---- [X:Num,Y:Num..Z:Num] = numsby (Y-X) X Z; ! /* Additional list enumeration operations on characters. These are not ! implemented as builtins and are actually pretty useless because of ! efficiency issues, but we provide them here anyway. */ ! ! [X:Char..] = list {X..}; ! [X:Char,Y:Char..] = list {X,Y..}; ! enum_from X:Char = list (streamenum_from X); ! ! /* Stream enumeration operations on numbers. */ {X:Num..} = numstream X; *************** *** 144,147 **** --- 152,171 ---- streamenum X:Num Y:Num = takewhile (<=Y) (numstream X); + /* Stream enumeration operations on characters. */ + + {X:Char..} = takewhile ischar (iterate (+1) X); + {X:Char,Y:Char..} = takewhile ischar (iterate (+D) X) if D<>0 + where D = Y-X; + streamenum_from X:Char = takewhile ischar (iterate (+1) X); + + {X:Char..Y:Char} = takewhile (<=Y) Xs + where Xs:Stream = {X..}; + {X:Char,Y:Char..Z:Char} = takewhile (<=Z) Xs where Xs:Stream = {X,Y..} if D>0 + where D = Y-X; + = takewhile (>=Z) Xs where Xs:Stream = {X,Y..} if D<0 + where D = Y-X; + streamenum X:Char Y:Char= takewhile (<=Y) Xs + where Xs:Stream = streamenum_from X; + /* These will work with arbitrary enumeration types. */ |