1 /** This file is part of Shapes.
3 ** Shapes is free software: you can redistribute it and/or modify
4 ** it under the terms of the GNU General Public License as published by
5 ** the Free Software Foundation, either version 3 of the License, or
8 ** Shapes is distributed in the hope that it will be useful,
9 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 ** GNU General Public License for more details.
13 ** You should have received a copy of the GNU General Public License
14 ** along with Shapes. If not, see <http://www.gnu.org/licenses/>.
16 ** Copyright 2014 Henrik Tidefelt
19 ##needs ..Shapes..Data / seq-support
22 ##lookin ..Shapes..Data
24 /***********************************************************************************
25 ** Elementary tests on integer ranges.
28 /** Sorting according to usual precedence.
30 incSeq: [range '0 '24]
31 decSeq: [range '24 '0 step:'~1]
32 IO..•stdout << [seq_string [separate ` ´ [sort incSeq (<)]]] << "{n}
33 IO..•stdout << [seq_string [separate ` ´ [sort decSeq (<)]]] << "{n}
35 /** Check the stability property of the sort.
37 lessFive: (\ x y → (x / '5) < (y / '5))
38 IO..•stdout << [seq_string [separate ` ´ [sort incSeq lessFive]]] << "{n}
39 IO..•stdout << [seq_string [separate ` ´ [sort decSeq lessFive]]] << "{n}
42 /***********************************************************************************
43 ** Everything that follows is a test of sorting sequences in lexiographic order.
46 /** Text input form of a sequence.
48 seqInputForm: \ seq → (String..newString << `[list ´ << [seq_string [separate ` ´ seq]] << `]´)
50 /** Data to be sorted.
65 /** Precedence test for sequences, using the operator < to compare elements.
67 seqLess: \ seq1 seq2 →
69 [cons ([nil? seq1] and [nil? seq2]) false]
70 [cons [nil? seq1] true]
71 [cons [nil? seq2] false]
78 [cons (v1 > v2) false]
79 [cons true [seqLess seq1.cdr seq2.cdr]]
85 /** Sort values, and show.
87 valuesSorted: [sort values seqLess]
88 IO..•stdout << [seq_string [separate "{n} [fmap seqInputForm valuesSorted]]] << "{n}