Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
4
Task/Collections/Apex/collections-1.apex
Normal file
4
Task/Collections/Apex/collections-1.apex
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
// Create an empty list of String
|
||||
List<String> my_list = new List<String>();
|
||||
// Create a nested list
|
||||
List<List<Set<Integer>>> my_list_2 = new List<List<Set<Integer>>>();
|
||||
6
Task/Collections/Apex/collections-2.apex
Normal file
6
Task/Collections/Apex/collections-2.apex
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
List<Integer> myList = new List<Integer>(); // Define a new list
|
||||
myList.add(47); // Adds a second element of value 47 to the end
|
||||
// of the list
|
||||
Integer i = myList.get(0); // Retrieves the element at index 0
|
||||
myList.set(0, 1); // Adds the integer 1 to the list at index 0
|
||||
myList.clear(); // Removes all elements from the list
|
||||
3
Task/Collections/Apex/collections-3.apex
Normal file
3
Task/Collections/Apex/collections-3.apex
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
String[] colors = new List<String>();
|
||||
List<String> colors = new String[1];
|
||||
colors[0] = 'Green';
|
||||
3
Task/Collections/Apex/collections-4.apex
Normal file
3
Task/Collections/Apex/collections-4.apex
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
Set<String> s1 = new Set<String>{'a', 'b + c'}; // Defines a new set with two elements
|
||||
Set<String> s2 = new Set<String>(s1); // Defines a new set that contains the
|
||||
// elements of the set created in the previous step
|
||||
4
Task/Collections/Apex/collections-5.apex
Normal file
4
Task/Collections/Apex/collections-5.apex
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
Set<Integer> s = new Set<Integer>(); // Define a new set
|
||||
s.add(1); // Add an element to the set
|
||||
System.assert(s.contains(1)); // Assert that the set contains an element
|
||||
s.remove(1); // Remove the element from the set
|
||||
3
Task/Collections/Apex/collections-6.apex
Normal file
3
Task/Collections/Apex/collections-6.apex
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
Map<String, String> country_currencies = new Map<String, String>();
|
||||
Map<ID, Set<String>> m = new Map<ID, Set<String>>();
|
||||
Map<String, String> MyStrings = new Map<String, String>{'a' => 'b', 'c' => 'd'.toUpperCase()};
|
||||
7
Task/Collections/Apex/collections-7.apex
Normal file
7
Task/Collections/Apex/collections-7.apex
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
Map<Integer, String> m = new Map<Integer, String>(); // Define a new map
|
||||
m.put(1, 'First entry'); // Insert a new key-value pair in the map
|
||||
m.put(2, 'Second entry'); // Insert a new key-value pair in the map
|
||||
System.assert(m.containsKey(1)); // Assert that the map contains a key
|
||||
String value = m.get(2); // Retrieve a value, given a particular key
|
||||
System.assertEquals('Second entry', value);
|
||||
Set<Integer> s = m.keySet(); // Return a set that contains all of the keys in the map
|
||||
8
Task/Collections/Axe/collections.axe
Normal file
8
Task/Collections/Axe/collections.axe
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
1→{L₁}
|
||||
2→{L₁+1}
|
||||
3→{L₁+2}
|
||||
4→{L₁+3}
|
||||
Disp {L₁}►Dec,i
|
||||
Disp {L₁+1}►Dec,i
|
||||
Disp {L₁+2}►Dec,i
|
||||
Disp {L₁+3}►Dec,i
|
||||
9
Task/Collections/EchoLisp/collections.echolisp
Normal file
9
Task/Collections/EchoLisp/collections.echolisp
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
(define my-collection ' ( 🌱 ☀️ ☔️ ))
|
||||
(set! my-collection (cons '🎥 my-collection))
|
||||
(set! my-collection (cons '🐧 my-collection))
|
||||
my-collection
|
||||
→ (🐧 🎥 🌱 ☀️ ☔️)
|
||||
|
||||
;; save it
|
||||
(local-put 'my-collection)
|
||||
→ my-collection
|
||||
17
Task/Collections/FreeBASIC/collections.freebasic
Normal file
17
Task/Collections/FreeBASIC/collections.freebasic
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
'create fixed size array of integers
|
||||
Dim a(1 To 5) As Integer = {1, 2, 3, 4, 5}
|
||||
Print a(2), a(4)
|
||||
|
||||
'create empty dynamic array of doubles
|
||||
Dim b() As Double
|
||||
' add two elements by first redimensioning the array to hold this number of elements
|
||||
Redim b(0 To 1)
|
||||
b(0) = 3.5 : b(1) = 7.1
|
||||
Print b(0), b(1)
|
||||
|
||||
'create 2 dimensional fixed size array of bytes
|
||||
Dim c(1 To 2, 1 To 2) As Byte = {{1, 2}, {3, 4}}
|
||||
Print c(1, 1), c(2,2)
|
||||
Sleep
|
||||
13
Task/Collections/Lingo/collections.lingo
Normal file
13
Task/Collections/Lingo/collections.lingo
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
-- list stuff
|
||||
l = [1, 2]
|
||||
l.add(3)
|
||||
l.add(4)
|
||||
put l
|
||||
-- [1, 2, 3, 4]
|
||||
|
||||
-- property list stuff
|
||||
pl = [#foo: 1, #bar: 2]
|
||||
pl[#foobar] = 3
|
||||
pl["barfoo"] = 4
|
||||
put pl
|
||||
-- [#foo: 1, #bar: 2, #foobar: 3, "barfoo": 4]
|
||||
6
Task/Collections/Nim/collections-1.nim
Normal file
6
Task/Collections/Nim/collections-1.nim
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
var a = [1,2,3,4,5,6,7,8,9]
|
||||
var b: array[128, int]
|
||||
b[9] = 10
|
||||
b[0..8] = a
|
||||
var c: array['a'..'d', float] = [1.0, 1.1, 1.2, 1.3]
|
||||
c['b'] = 10000
|
||||
11
Task/Collections/Nim/collections-2.nim
Normal file
11
Task/Collections/Nim/collections-2.nim
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
var d = @[1,2,3,5,6,7,8,9]
|
||||
d.add(10)
|
||||
d.add([11,12,13,14])
|
||||
d[0] = 0
|
||||
|
||||
var e: seq[float] = @[]
|
||||
e.add(15.5)
|
||||
|
||||
var f = newSeq[string]()
|
||||
f.add("foo")
|
||||
f.add("bar")
|
||||
7
Task/Collections/Nim/collections-3.nim
Normal file
7
Task/Collections/Nim/collections-3.nim
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
var g = (13, 13, 14)
|
||||
g[0] = 12
|
||||
|
||||
var h: tuple[key: string, val: int] = ("foo", 100)
|
||||
|
||||
# A sequence of key-val tuples:
|
||||
var i = {"foo": 12, "bar": 13}
|
||||
6
Task/Collections/Nim/collections-4.nim
Normal file
6
Task/Collections/Nim/collections-4.nim
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
var j: set[char]
|
||||
j.incl('X')
|
||||
|
||||
var k = {'a'..'z', '0'..'9'}
|
||||
|
||||
j = j + k
|
||||
7
Task/Collections/Nim/collections-5.nim
Normal file
7
Task/Collections/Nim/collections-5.nim
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import tables
|
||||
var l = initTable[string, int]()
|
||||
l["foo"] = 12
|
||||
l["bar"] = 13
|
||||
|
||||
var m = {"foo": 12, "bar": 13}.toTable
|
||||
m["baz"] = 14
|
||||
6
Task/Collections/Nim/collections-6.nim
Normal file
6
Task/Collections/Nim/collections-6.nim
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import sets
|
||||
var n = initSet[string]()
|
||||
n.incl("foo")
|
||||
|
||||
var o = ["foo", "bar", "baz"].toSet
|
||||
o.incl("foobar")
|
||||
4
Task/Collections/Nim/collections-7.nim
Normal file
4
Task/Collections/Nim/collections-7.nim
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
import queues
|
||||
var p = initQueue[int]()
|
||||
p.add(12)
|
||||
p.add(13)
|
||||
1
Task/Collections/Oforth/collections-1.oforth
Normal file
1
Task/Collections/Oforth/collections-1.oforth
Normal file
|
|
@ -0,0 +1 @@
|
|||
[ 1, 1.2, "abcd", [ 1, 2, 3 ] ]
|
||||
1
Task/Collections/Oforth/collections-2.oforth
Normal file
1
Task/Collections/Oforth/collections-2.oforth
Normal file
|
|
@ -0,0 +1 @@
|
|||
ListBuffer new dup add(10) dup add("aaa") dup add(Date now) dup add(1.3) println
|
||||
4
Task/Collections/Phix/collections-1.phix
Normal file
4
Task/Collections/Phix/collections-1.phix
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
sequence collection = {}
|
||||
collection = append(collection,"one")
|
||||
collection = prepend(collection,2)
|
||||
? collection -- {2,"one"}
|
||||
7
Task/Collections/Phix/collections-2.phix
Normal file
7
Task/Collections/Phix/collections-2.phix
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
setd("one",0)
|
||||
setd(2,0)
|
||||
function visitor(object key, object /*data*/, object /*user_data*/)
|
||||
?key
|
||||
return 1
|
||||
end function
|
||||
traverse_dict(routine_id("visitor")) -- shows 2, "one"
|
||||
5
Task/Collections/Sidef/collections-1.sidef
Normal file
5
Task/Collections/Sidef/collections-1.sidef
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# creating an empty array and adding values
|
||||
var a = [] #=> []
|
||||
a[0] = 1 #=> [1]
|
||||
a[3] = "abc" #=> [1, nil, nil, "abc"]
|
||||
a << 3.14 #=> [1, nil, nil, "abc", 3.14]
|
||||
5
Task/Collections/Sidef/collections-2.sidef
Normal file
5
Task/Collections/Sidef/collections-2.sidef
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# creating an empty hash
|
||||
var h = Hash() #=> Hash()
|
||||
h{:foo} = 1 #=> Hash("foo"=>1)
|
||||
h{:bar} = 2.4 #=> Hash("foo"=>1, "bar"=>2.4)
|
||||
h{:bar} += 3 #=> Hash("foo"=>1, "bar"=>5.4)
|
||||
14
Task/Collections/Sidef/collections-3.sidef
Normal file
14
Task/Collections/Sidef/collections-3.sidef
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# create a simple pair
|
||||
var p = Pair('a', 'b')
|
||||
say p.first; #=> 'a'
|
||||
say p.second; #=> 'b'
|
||||
|
||||
# create a pair of pairs
|
||||
var pair = 'foo':'bar':'baz':(); # => Pair('foo', Pair('bar', Pair('baz', nil)))
|
||||
|
||||
# iterate over the values of a pair of pairs
|
||||
loop {
|
||||
say pair.first; #=> 'foo', 'bar', 'baz'
|
||||
pair = pair.second;
|
||||
pair == nil && break;
|
||||
}
|
||||
15
Task/Collections/Sidef/collections-4.sidef
Normal file
15
Task/Collections/Sidef/collections-4.sidef
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# creating a struct
|
||||
struct Person {
|
||||
String name,
|
||||
Number age,
|
||||
String sex
|
||||
}
|
||||
|
||||
var a = Person("John Smith", 41, :man)
|
||||
|
||||
a.age += 1 # increment age
|
||||
a.name = "Dr. #{a.name}" # update name
|
||||
|
||||
say a.name #=> "Dr. John Smith"
|
||||
say a.age #=> 42
|
||||
say a.sex #=> "man"
|
||||
22
Task/Collections/Visual-FoxPro/collections.visual
Normal file
22
Task/Collections/Visual-FoxPro/collections.visual
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
LOCAL loColl As Collection, o, a1, a2, a3
|
||||
a1 = CREATEOBJECT("animal", "dog", 4)
|
||||
a2 = CREATEOBJECT("animal", "chicken", 2)
|
||||
a3 = CREATEOBJECT("animal", "snake", 0)
|
||||
loColl = NEWOBJECT("Collection")
|
||||
loColl.Add(a1)
|
||||
loColl.Add(a2)
|
||||
loColl.Add(a3)
|
||||
|
||||
FOR EACH o IN loColl FOXOBJECT
|
||||
? o.Name, o.Legs
|
||||
ENDFOR
|
||||
|
||||
DEFINE CLASS animal As Custom
|
||||
Legs = 0
|
||||
|
||||
PROCEDURE Init(tcName, tnLegs)
|
||||
THIS.Name = tcName
|
||||
THIS.Legs = tnLegs
|
||||
ENDPROC
|
||||
|
||||
ENDDEFINE
|
||||
16
Task/Collections/Wren/collections.wren
Normal file
16
Task/Collections/Wren/collections.wren
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
var list = [] // Empty Array
|
||||
list = [1,2,3,4]
|
||||
list.add(5)
|
||||
list.clear()
|
||||
list = [0] * 10
|
||||
list.count // 10
|
||||
|
||||
var map = {}
|
||||
map["key"] = "value"
|
||||
map[3] = 31
|
||||
map.count // 2
|
||||
map.clear()
|
||||
|
||||
for (e in map.keys) {
|
||||
// Do stuff
|
||||
}
|
||||
1
Task/Collections/jq/collections-1.jq
Normal file
1
Task/Collections/jq/collections-1.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"a": 1} == {a: 1}
|
||||
1
Task/Collections/jq/collections-2.jq
Normal file
1
Task/Collections/jq/collections-2.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
"a" as $key | 1 as $value | {($key): $value}
|
||||
1
Task/Collections/jq/collections-3.jq
Normal file
1
Task/Collections/jq/collections-3.jq
Normal file
|
|
@ -0,0 +1 @@
|
|||
[0,1,2] | .[0] = 10
|
||||
Loading…
Add table
Add a link
Reference in a new issue