September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -1,34 +1,43 @@
use framework "Foundation"
use scripting additions
on sort:lst
tell current application
return ((its (NSArray's arrayWithArray:lst))'s ¬
sortedArrayUsingDescriptors:{its (NSSortDescriptor's ¬
sortDescriptorWithKey:"self" ascending:true selector:"compare:")}) as list
end tell
end sort:
-- sort :: [a] -> [a]
on sort(lst)
((current application's NSArray's arrayWithArray:lst)'s ¬
sortedArrayUsingSelector:"compare:") as list
end sort
-- TEST -----------------------------------------------------------------------
on run
map(sort_, [[9, 1, 8, 2, 8, 3, 7, 0, 4, 6, 5], ¬
["alpha", "beta", "gamma", "delta", "epsilon", "zeta", "eta", "theta", "iota", "kappa", "lambda", "mu"]])
map(sort, [[9, 1, 8, 2, 8, 3, 7, 0, 4, 6, 5], ¬
["alpha", "beta", "gamma", "delta", "epsilon", "zeta", "eta", ¬
"theta", "iota", "kappa", "lambda", "mu"]])
end run
-- GENERIC FUNCTION FOR THE TEST
-- GENERIC FUNCTIONS ---------------------------------------------------------
-- map :: (a -> b) -> [a] -> [b]
on map(f, xs)
script mf
property lambda : f
end script
set lng to length of xs
set lst to {}
repeat with i from 1 to lng
set end of lst to mf's lambda(item i of xs, i, xs)
end repeat
return lst
tell mReturn(f)
set lng to length of xs
set lst to {}
repeat with i from 1 to lng
set end of lst to |λ|(item i of xs, i, xs)
end repeat
return lst
end tell
end map
-- Lift 2nd class handler function into 1st class script wrapper
-- mReturn :: Handler -> Script
on mReturn(f)
if class of f is script then
f
else
script
property |λ| : f
end script
end if
end mReturn

View file

@ -0,0 +1,14 @@
' Sort an integer array
DECLARE values[5] TYPE NUMBER
values[0] = 23
values[1] = 32
values[2] = 12
values[3] = 21
values[4] = 01
SORT values
FOR i = 0 TO 3
PRINT values[i], ", ";
NEXT
PRINT values[4]

View file

@ -1,12 +1,9 @@
#import system.
#import system'routines.
#import extensions.
import system'routines.
import extensions.
#symbol program =
program =
[
#var unsorted := (6, 2, 7, 8, 3, 1, 10, 5, 4, 9).
var unsorted := (6, 2, 7, 8, 3, 1, 10, 5, 4, 9).
unsorted sort:ifOrdered.
console writeLine:unsorted.
console printLine(unsorted clone; sort:ifOrdered).
].

View file

@ -0,0 +1,12 @@
Public Sub Main()
Dim iArray As Integer[] = [8, 2, 5, 9, 1, 3, 6, 7, 4]
Dim iTemp As Integer
Dim sOutput As String
For Each iTemp In iArray.Sort()
sOutput &= iTemp & ", "
Next
Print Left(sOutput, -2)
End

View file

@ -0,0 +1,7 @@
// version 1.0.6
fun main(args: Array<String>) {
val ints = intArrayOf(6, 2, 7, 8, 3, 1, 10, 5, 4, 9)
ints.sort()
println(ints.joinToString(prefix = "[", postfix = "]"))
}

View file

@ -1,6 +0,0 @@
import algorithm
var a: array[0..8,int] = [2,3,5,8,4,1,6,9,7]
a.sort(system.cmp[int], Ascending)
for x in a:
echo(x)

View file

@ -0,0 +1,3 @@
a = .array~of(4, 1, 6, -2, 99, -12)
say "The sorted numbers are"
say a~sortWith(.numericComparator~new)~makeString

View file

@ -1,15 +0,0 @@
Construct a list of numbers
<@ LETCNSLSTLIT>L|65^84^1^25^77^4^47^2^42^44^41^25^69^3^51^45^4^39^</@>
Numbers sort as strings
<@ ACTSRTENTLST>L</@>
<@ SAYDMPLST>L</@>
<@ ACTSRTENTLSTLIT>L|__StringDescending</@>
<@ SAYDMPLST>L</@>
Construct another list of numbers
<@ LETCNSLSTLIT>list|65^84^1^25^77^4^47^2^42^44^41^25^69^3^51^45^4^39^</@>
Numbers sorted as numbers
<@ ACTSRTENTLSTLIT>list|__Numeric</@>
<@ SAYDMPLST>list</@>
<@ ACTSRTENTLSTLIT>list|__NumericDescending</@>
<@ SAYDMPLST>list</@>

View file

@ -1,15 +0,0 @@
Construct a list of numbers
Numbers sort as strings
1^2^25^25^3^39^4^4^41^42^44^45^47^51^65^69^77^84^
84^77^69^65^51^47^45^44^42^41^4^4^39^3^25^25^2^1^
Construct another list of numbers
Numbers sorted as numbers
1^2^3^4^4^25^25^39^41^42^44^45^47^51^65^69^77^84^
84^77^69^65^51^47^45^44^42^41^39^25^25^4^4^3^2^1^

View file

@ -0,0 +1,6 @@
> (import (srfi 132))
> (list-sort < '(9 -2 1 2 8 0 1 2))
(-2 0 1 1 2 2 8 9)
> (vector-sort < #(9 -2 1 2 8 0 1 2))
#(-2 0 1 1 2 2 8 9)

View file

@ -0,0 +1,5 @@
> (import (srfi 95))
> (sort '(9 -2 1 2 8 0 1 2) <)
(-2 0 1 1 2 2 8 9)
> (sort #(9 -2 1 2 8 0 1 2) <)
#(-2 0 1 1 2 2 8 9)

View file

@ -0,0 +1,17 @@
mata
: a=2\9\4\7\5\3\6\1\8
: sort(a,1)
1
+-----+
1 | 1 |
2 | 2 |
3 | 3 |
4 | 4 |
5 | 5 |
6 | 6 |
7 | 7 |
8 | 8 |
9 | 9 |
+-----+
end

View file

@ -0,0 +1 @@
a:=L(4,5,2,6); a.sort(); a.println() //--> L(2,4,5,6)

View file

@ -0,0 +1,3 @@
a:=T(4,5,2,6); b:=a.sort();
b.println(); //--> L(2,4,5,6)
a.println(); //--> L(4,5,2,6)