Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,33 @@
define sortarray( // params are set by position
items::array, // required param
ordering::string = 'lexicographic', // optional param
column::integer = 1,
reverse::boolean = false
) => {
// sorting process
local(sorteditems = array)
// Lasso has no build in method to sort an array of arrays by position in the contained arrays
// But a method could be built for it
return #sorteditems
}
define sortarray(
-items::array, // required param
-ordering::string = 'lexicographic', // optional param
-column::integer = 1,
-reverse::boolean = false
) => sortarray(#items, #ordering, #column, #reverse)
local(items = array(
array(10, 'red', 'Volvo'),
array(15, 'gren', 'Ford'),
array(48, 'yellow', 'Kia'),
array(12, 'black', 'Holden'),
array(19, 'brown', 'Fiat'),
array(8, 'pink', 'Batmobile'),
array(74, 'orange', 'Bicycle')
))
sortarray(-items = #items, -reverse)
sortarray(#items)

View file

@ -0,0 +1,22 @@
import algorithm, strutils, future
proc printTable(a) =
for row in a:
for x in row: stdout.write x, repeatChar(4 - x.len)
echo ""
echo ""
proc sortTable(a: seq[seq[string]], column = 0, reverse = false,
ordering: (proc(a,b: string): int) = system.cmp) : seq[seq[string]] =
let order = if reverse: Descending else: Ascending
result = a
result.sort(proc(x,y:seq[string]):int = ordering(x[column],y[column]), order)
const data = @[@["a", "b", "c"], @["", "q", "z"], @["zap", "zip", "Zot"]]
printTable data
printTable sortTable(data)
printTable sortTable(data, column = 2)
printTable sortTable(data, column = 1)
printTable sortTable(data, column = 1, reverse = true)
printTable sortTable(data, ordering = (a,b) => cmp[int](b.len,a.len))

View file

@ -0,0 +1,6 @@
function increment(integer i, integer inc=1)
return i+inc
end function
?increment(5) -- shows 6
?increment(5,2) -- shows 7

View file

@ -0,0 +1 @@
printf(1,"%d records sorted in %3.2s\n",{records,time()-t0})

View file

@ -0,0 +1,22 @@
integer sortcol = 0
integer sortdir = 1
function by_column(integer i, integer j)
return sortdir*compare(data[i][sortcol],data[j][sortcol])
end function
sequence tags = tagset(table_size) -- {1,2,..table_size}
function click_cb(Ihandle self, integer l, integer c, atom pStatus)
string sortc
...
sortc = sprintf("SORTSIGN%d",c)
sortdir = iff(IupGetAttribute(self,sortc)="DOWN"?-1:1)
IupSetAttribute(self,sortc,iff(sortdir=-1?"UP":"DOWN"))
sortcol = c
tags = custom_sort(routine_id("by_column"),tags)
function value_cb(Ihandle /*self*/, integer l, integer c)
l = tags[l]
return data[l][c]
end function

View file

@ -0,0 +1,16 @@
func table_sort(table, ordering: '<=>', column: 0, reverse: false) {
if (reverse) {
table.sort {|a,b| b[column].$ordering(a[column])}
} else {
table.sort {|a,b| a[column].$ordering(b[column])}
}
}
# Quick example:
var table = [
["Ottowa", "Canada"],
["Washington", "USA"],
["Mexico City", "Mexico"],
];
say table_sort(table, column: 1);

View file

@ -0,0 +1,9 @@
class String {
method my_sort(arg) {
(self.len <=> arg.len) ->
|| (self.lc <=> arg.lc) ->
|| (self <=> arg)
}
}
say table_sort(table, column: 1, ordering: 'my_sort');

View file

@ -0,0 +1,5 @@
enum SortOrder { case kOrdNone, kOrdLex, kOrdByAddress, kOrdNumeric }
func sortTable(table: [[String]], less: (String,String)->Bool = (<), column: Int = 0, reversed: Bool = false) {
// . . . Actual sort goes here . . .
}

View file

@ -0,0 +1,3 @@
def bar: 2 *.;
def foo: {"a": bar};

View file

@ -0,0 +1 @@
def less_than_or_equal: .[0] <= .[1];

View file

@ -0,0 +1,9 @@
def sorter(options):
sort_table( if (options|has("ordering")) then options.ordering
else less_than_or_equal
end;
options.column or 0;
options.reverse or false );
# If jq > 1.4 is being used, we may also define:
def sorter: sorter({});

View file

@ -0,0 +1,6 @@
[1,2] | sorter({ "reverse": true, "ordering": less_than_or_equal } )
[1,2] | sorter({ "reverse": true })
# If sorter/0 has also been defined:
[1,2] | sorter