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,21 @@
shared void run() {
value myMap = map {
"foo" -> 5,
"bar" -> 10,
"baz" -> 15
};
for(key in myMap.keys) {
print(key);
}
for(item in myMap.items) {
print(item);
}
for(key->item in myMap) {
print("``key`` maps to ``item``");
}
}

View file

@ -0,0 +1,24 @@
(lib 'hash) ;; load hash.lib
(define H (make-hash))
;; fill hash table
(hash-set H 'Simon 42)
(hash-set H 'Albert 666)
(hash-set H 'Antoinette 33)
;; iterate over (key . value ) pairs
(for ([kv H]) (writeln kv))
(Simon . 42)
(Albert . 666)
(Antoinette . 33)
;; iterate over keys
(for ([k (hash-keys H)]) (writeln 'key-> k))
key-> Simon
key-> Albert
key-> Antoinette
;; iterate over values
(for ([v (hash-values H)]) (writeln 'value-> v))
value-> 42
value-> 666
value-> 33

View file

@ -0,0 +1,11 @@
LOCAL arr := { 6 => 16, "eight" => 8, "eleven" => 11 }
LOCAL x
FOR EACH x IN arr
// key, value
? x:__enumKey(), x
// or key only
? x:__enumKey()
// or value only
? x
NEXT

View file

@ -0,0 +1,7 @@
(let ((data '(#(key1 "foo") #(key2 "bar")))
(hash (: dict from_list data)))
(: dict fold
(lambda (key val accum)
(: io format '"~s: ~s~n" (list key val)))
0
hash))

View file

@ -0,0 +1,6 @@
(let ((data '(#(key1 "foo") #(key2 "bar")))
(hash (: dict from_list data)))
(: lists map
(lambda (key)
(: io format '"~s~n" (list key)))
(: dict fetch_keys hash)))

View file

@ -0,0 +1,29 @@
//iterate over associative array
//Lasso maps
local('aMap' = map('weight' = 112,
'height' = 45,
'name' = 'jason'))
' Map output: \n '
#aMap->forEachPair => {^
//display pair, then show accessing key and value individually
#1+'\n '
#1->first+': '+#1->second+'\n '
^}
//display keys and values separately
'\n'
' Map Keys: '+#aMap->keys->join(',')+'\n'
' Map values: '+#aMap->values->join(',')+'\n'
//display using forEach
'\n'
' Use ForEach to iterate Map keys: \n'
#aMap->keys->forEach => {^
#1+'\n'
^}
'\n'
' Use ForEach to iterate Map values: \n'
#aMap->values->forEach => {^
#1+'\n'
^}
//the {^ ^} indicates that output should be printed (AutoCollect) ,
// if output is not desired, just { } is used

View file

@ -0,0 +1,11 @@
hash = [#key1:"value1", #key2:"value2", #key3:"value3"]
-- iterate over key-value pairs
repeat with i = 1 to hash.count
put hash.getPropAt(i) & "=" & hash[i]
end repeat
-- iterating over values only can be written shorter
repeat with val in hash
put val
end repeat

View file

@ -0,0 +1,24 @@
put 3 into fruit["apples"]
put 5 into fruit["pears"]
put 6 into fruit["oranges"]
put "none" into fruit["bananas"]
put "Keys:" & cr & the keys of fruit & cr into tTmp
put "Values 1:" & tab after tTmp
repeat for each line tKey in the keys of fruit
put fruit[tkey] & comma after tTmp
end repeat
-- need to copy array as combine will change variable
put fruit into fruit2
combine fruit2 using comma
put cr & "Values2:" & tab after tTmp
repeat for each item f2val in fruit2
put f2val & comma after tTmp
end repeat
combine fruit using return and ":"
put cr & "Key:Values" & cr & fruit after tTmp
-- alternatively, use same loop as for values 1 with tkey && fruit[tKey]
put tTmp

View file

@ -0,0 +1,12 @@
Keys:
apples
pears
oranges
bananas
Values 1: 3,5,6,none,
Values2: 3,none,6,5,
Key:Values
apples:3
bananas:none
oranges:6
pears:5

View file

@ -0,0 +1,23 @@
import tables
var t: TTable[int,string] = initTable[int,string]()
t[1] = "one"
t[2] = "two"
t[3] = "three"
t.add(4,"four")
echo "t has " & $t.len & " elements"
echo "has t key 4? " & $t.hasKey(4)
echo "has t key 5? " & $t.hasKey(5)
#iterate keys
echo "key iteration:"
for k in t.keys:
echo "at[" & $k & "]=" & t[k]
#itetate pairs
echo "pair iteration:"
for k,v in t.pairs:
echo "at[" & $k & "]=" & v

View file

@ -0,0 +1,9 @@
setd("one",1)
setd(2,"duo")
setd({3,4},{5,"six"})
function visitor(object key, object data, object /*userdata*/)
?{key,data}
return 1 -- (continue traversal)
end function
traverse_dict(routine_id("visitor"))

View file

@ -0,0 +1,4 @@
include builtins\map.e
?pairs()
?keys()
?values()

View file

@ -0,0 +1,4 @@
mydictionary = (red=0xff0000, green=0x00ff00, blue=0x0000ff)
mydictionary each (key, val): (key, ":", val, "\n") join print.
mydictionary each (key): (key, "\n") join print.

View file

@ -0,0 +1,19 @@
var hash = Hash.new(
key1 => 'value1',
key2 => 'value2',
)
# Iterate over key-value pairs
hash.each { |key, value|
say "#{key}: #{value}";
}
# Iterate only over keys
hash.keys.each { |key|
say key;
}
# Iterate only over values
hash.values.each { |value|
say value;
}

View file

@ -0,0 +1,9 @@
let myMap = [
"hello": 13,
"world": 31,
"!" : 71 ]
// iterating over key-value pairs:
for (key, value) in myMap {
println("key = \(key), value = \(value)")
}

View file

@ -0,0 +1,3 @@
h <- (table 'a 1 'b 2)
each (key val) table
prn key " " val