September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,3 +1,4 @@
|
|||
l_query(l, 2);
|
||||
l_head(l);
|
||||
l_q_text(l, 1);
|
||||
l_query(l, 2)
|
||||
l_head(l)
|
||||
l_q_text(l, 1)
|
||||
l[3]
|
||||
|
|
|
|||
|
|
@ -1,2 +1,3 @@
|
|||
r_p_integer(r, "key1", 7);
|
||||
r_put(r, "key2", "a string");
|
||||
r["key3"] = .25;
|
||||
|
|
|
|||
|
|
@ -1,2 +1,3 @@
|
|||
r_query(r, "key1");
|
||||
r_tail(r);
|
||||
r_query(r, "key1")
|
||||
r_tail(r)
|
||||
r["key2"]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
// Creates and initializes a new Array
|
||||
#var intArray := (1, 2, 3, 4, 5).
|
||||
var intArray := (1, 2, 3, 4, 5).
|
||||
|
||||
#var stringArr := Array new:5.
|
||||
stringArr@0 := "string".
|
||||
var stringArr := Array new:5.
|
||||
stringArr[0] := "string".
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
//Create and initialize ArrayList
|
||||
#var myAl := ArrayList new += "Hello" += "World" += "!".
|
||||
var myAl := ArrayList new; append:"Hello"; append:"World"; append:"!".
|
||||
|
||||
//Create and initialize List
|
||||
#var myList := List new += "Hello" += "World" += "!".
|
||||
var myList := List new; append:"Hello"; append:"World"; append:"!".
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
//Create a dictionary
|
||||
#var dict := Dictionary new.
|
||||
dict@"Hello" := "World".
|
||||
dict@"Key" := "Value".
|
||||
var dict := Dictionary new.
|
||||
dict["Hello"] := "World".
|
||||
dict["Key"] := "Value".
|
||||
|
|
|
|||
3
Task/Collections/Fortran/collections-1.f
Normal file
3
Task/Collections/Fortran/collections-1.f
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
REAL A(36) !Declares a one-dimensional array A(1), A(2), ... A(36)
|
||||
A(1) = 1 !Assigns a value to the first element.
|
||||
A(2) = 3*A(1) + 5 !The second element gets 8.
|
||||
7
Task/Collections/Fortran/collections-2.f
Normal file
7
Task/Collections/Fortran/collections-2.f
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
TYPE(MIXED) !Name the "type".
|
||||
INTEGER COUNTER !Its content is listed.
|
||||
REAL WEIGHT,DEPTH
|
||||
CHARACTER*28 MARKNAME
|
||||
COMPLEX PATH(6) !The mixed collection includes an array.
|
||||
END TYPE MIXED
|
||||
TYPE(MIXED) TEMP,A(6) !Declare some items of that type.
|
||||
19
Task/Collections/Haskell/collections-5.hs
Normal file
19
Task/Collections/Haskell/collections-5.hs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import Data.Array (Array, listArray, Ix, (!))
|
||||
|
||||
triples :: Array Int (Char, String, String)
|
||||
triples =
|
||||
listArray (0, 11) $
|
||||
zip3
|
||||
"鼠牛虎兔龍蛇馬羊猴鸡狗豬" -- 生肖 shengxiao – symbolic animals
|
||||
(words "shǔ niú hǔ tù lóng shé mǎ yáng hóu jī gǒu zhū")
|
||||
(words "rat ox tiger rabbit dragon snake horse goat monkey rooster dog pig")
|
||||
|
||||
indexedItem
|
||||
:: Ix i
|
||||
=> Array i (Char, String, String) -> i -> String
|
||||
indexedItem a n =
|
||||
let (c, w, w1) = a ! n
|
||||
in c : unwords ["\t", w, w1]
|
||||
|
||||
main :: IO ()
|
||||
main = (putStrLn . unlines) $ indexedItem triples <$> [2, 4, 6]
|
||||
20
Task/Collections/Haskell/collections-6.hs
Normal file
20
Task/Collections/Haskell/collections-6.hs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import qualified Data.Map as M
|
||||
import Data.Maybe (isJust)
|
||||
|
||||
mapSample :: M.Map String Int
|
||||
mapSample =
|
||||
M.fromList
|
||||
[ ("alpha", 1)
|
||||
, ("beta", 2)
|
||||
, ("gamma", 3)
|
||||
, ("delta", 4)
|
||||
, ("epsilon", 5)
|
||||
, ("zeta", 6)
|
||||
]
|
||||
|
||||
maybeValue :: String -> Maybe Int
|
||||
maybeValue = flip M.lookup mapSample
|
||||
|
||||
main :: IO ()
|
||||
main =
|
||||
print $ sequence $ filter isJust (maybeValue <$> ["beta", "delta", "zeta"])
|
||||
10
Task/Collections/Haskell/collections-7.hs
Normal file
10
Task/Collections/Haskell/collections-7.hs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import qualified Data.Set as S
|
||||
|
||||
setA :: S.Set String
|
||||
setA = S.fromList ["alpha", "beta", "gamma", "delta", "epsilon"]
|
||||
|
||||
setB :: S.Set String
|
||||
setB = S.fromList ["delta", "epsilon", "zeta", "eta", "theta"]
|
||||
|
||||
main :: IO ()
|
||||
main = (print . S.toList) (S.intersection setA setB)
|
||||
43
Task/Collections/Kotlin/collections.kotlin
Normal file
43
Task/Collections/Kotlin/collections.kotlin
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import java.util.PriorityQueue
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
// generic array
|
||||
val ga = arrayOf(1, 2, 3)
|
||||
println(ga.joinToString(prefix = "[", postfix = "]"))
|
||||
|
||||
// specialized array (one for each primitive type)
|
||||
val da = doubleArrayOf(4.0, 5.0, 6.0)
|
||||
println(da.joinToString(prefix = "[", postfix = "]"))
|
||||
|
||||
// immutable list
|
||||
val li = listOf<Byte>(7, 8, 9)
|
||||
println(li)
|
||||
|
||||
// mutable list
|
||||
val ml = mutableListOf<Short>()
|
||||
ml.add(10); ml.add(11); ml.add(12)
|
||||
println(ml)
|
||||
|
||||
// immutable map
|
||||
val hm = mapOf('a' to 97, 'b' to 98, 'c' to 99)
|
||||
println(hm)
|
||||
|
||||
// mutable map
|
||||
val mm = mutableMapOf<Char, Int>()
|
||||
mm.put('d', 100); mm.put('e', 101); mm.put('f', 102)
|
||||
println(mm)
|
||||
|
||||
// immutable set (duplicates not allowed)
|
||||
val se = setOf(1, 2, 3)
|
||||
println(se)
|
||||
|
||||
// mutable set (duplicates not allowed)
|
||||
val ms = mutableSetOf<Long>()
|
||||
ms.add(4L); ms.add(5L); ms.add(6L)
|
||||
println(ms)
|
||||
|
||||
// priority queue (imported from Java)
|
||||
val pq = PriorityQueue<String>()
|
||||
pq.add("First"); pq.add("Second"); pq.add("Third")
|
||||
println(pq)
|
||||
}
|
||||
5
Task/Collections/OoRexx/collections-1.rexx
Normal file
5
Task/Collections/OoRexx/collections-1.rexx
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
a = .array~new(4) -- creates an array of 4 items, with all slots empty
|
||||
say a~size a~items -- size is 4, but there are 0 items
|
||||
a[1] = "Fred" -- assigns a value to the first item
|
||||
a[5] = "Mike" -- assigns a value to the fifth slot, expanding the size
|
||||
say a~size a~items -- size is now 5, with 2 items
|
||||
9
Task/Collections/OoRexx/collections-2.rexx
Normal file
9
Task/Collections/OoRexx/collections-2.rexx
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
l = .list~new -- lists have no inherent size
|
||||
index = l~insert('123') -- adds an item to this list, returning the index
|
||||
l~insert('Fred', .nil) -- inserts this at the beginning
|
||||
l~insert('Mike') -- adds this to the end
|
||||
l~insert('Rick', index) -- inserts this after '123'
|
||||
l[index] = l[index] + 1 -- the original item is now '124'
|
||||
do item over l -- iterate over the items, displaying them in order
|
||||
say item
|
||||
end
|
||||
7
Task/Collections/OoRexx/collections-3.rexx
Normal file
7
Task/Collections/OoRexx/collections-3.rexx
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
q = .queue~of(2,4,6) -- creates a queue containing 3 items
|
||||
say q[1] q[3] -- displays "2 6"
|
||||
i = q~pull -- removes the first item
|
||||
q~queue(i) -- adds it to the end
|
||||
say q[1] q[3] -- displays "4 2"
|
||||
q[1] = q[1] + 1 -- updates the first item
|
||||
say q[1] q[3] -- displays "5 2"
|
||||
4
Task/Collections/OoRexx/collections-4.rexx
Normal file
4
Task/Collections/OoRexx/collections-4.rexx
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
t = .table~new
|
||||
t['abc'] = 1
|
||||
t['def'] = 2
|
||||
say t['abc'] t['def'] -- displays "1 2"
|
||||
12
Task/Collections/OoRexx/collections-5.rexx
Normal file
12
Task/Collections/OoRexx/collections-5.rexx
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
t = .table~new -- a table example to demonstrate the difference
|
||||
t['abc'] = 1 -- sets an item at index 'abc'
|
||||
t['abc'] = 2 -- updates that item
|
||||
say t~items t['abc'] -- displays "1 2"
|
||||
r = .relation~new
|
||||
r['abc'] = 1 -- sets an item at index 'abc'
|
||||
r['abc'] = 2 -- adds an additional item at the same index
|
||||
say r~items r['abc'] -- displays "2 2" this has two items in it now
|
||||
|
||||
do item over r~allAt('abc') -- retrieves all items at the index 'abc'
|
||||
say item
|
||||
end
|
||||
4
Task/Collections/OoRexx/collections-6.rexx
Normal file
4
Task/Collections/OoRexx/collections-6.rexx
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
d = .directory~new
|
||||
d['abc'] = 1
|
||||
d['def'] = 2
|
||||
say d['abc'] d['def'] -- displays "1 2"
|
||||
4
Task/Collections/OoRexx/collections-7.rexx
Normal file
4
Task/Collections/OoRexx/collections-7.rexx
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
d = .directory~new
|
||||
d~abc = 1
|
||||
d~def = 2
|
||||
say d~abc d~def -- displays "1 2"
|
||||
7
Task/Collections/OoRexx/collections-8.rexx
Normal file
7
Task/Collections/OoRexx/collections-8.rexx
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
s = .set~new
|
||||
text = "the quick brown fox jumped over the lazy dog"
|
||||
do word over text~makearray(' ')
|
||||
s~put(word)
|
||||
end
|
||||
|
||||
say "text has" text~words", but only" s~items "unique words"
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
my $s = KeySet.new: <a b c>;
|
||||
$s ∪= <d e f>;
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
my $bag = bag <b a k l a v a>;
|
||||
my $newbag = $bag ∪ <b e e f>;
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
my $b = KeySet.new: <b a k l a v a>;
|
||||
$b ∪= <d e f>;
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
my $tail = d => e => f => Nil;
|
||||
my $new = a => b => c => $tail;
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
my $obj = Something.new: foo => 1, bar => 2;
|
||||
my $newobj = $obj but role { has $.baz = 3 } # anonymous mixin
|
||||
47
Task/Collections/PowerShell/collections-1.psh
Normal file
47
Task/Collections/PowerShell/collections-1.psh
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
# Create an Array by separating the elements with commas:
|
||||
$array = "one", 2, "three", 4
|
||||
|
||||
# Using explicit syntax:
|
||||
$array = @("one", 2, "three", 4)
|
||||
|
||||
# Send the values back into individual variables:
|
||||
$var1, $var2, $var3, $var4 = $array
|
||||
|
||||
# An array of several integer ([int]) values:
|
||||
$array = 0, 1, 2, 3, 4, 5, 6, 7
|
||||
|
||||
# Using the range operator (..):
|
||||
$array = 0..7
|
||||
|
||||
# Strongly typed:
|
||||
[int[]] $stronglyTypedArray = 1, 2, 4, 8, 16, 32, 64, 128
|
||||
|
||||
# An empty array:
|
||||
$array = @()
|
||||
|
||||
# An array with a single element:
|
||||
$array = @("one")
|
||||
|
||||
# I suppose this would be a jagged array:
|
||||
$jaggedArray = @((11, 12, 13),
|
||||
(21, 22, 23),
|
||||
(31, 32, 33))
|
||||
|
||||
$jaggedArray | Format-Wide {$_} -Column 3 -Force
|
||||
|
||||
$jaggedArray[1][1] # returns 22
|
||||
|
||||
# A Multi-dimensional array:
|
||||
$multiArray = New-Object -TypeName "System.Object[,]" -ArgumentList 6,6
|
||||
|
||||
for ($i = 0; $i -lt 6; $i++)
|
||||
{
|
||||
for ($j = 0; $j -lt 6; $j++)
|
||||
{
|
||||
$multiArray[$i,$j] = ($i + 1) * 10 + ($j + 1)
|
||||
}
|
||||
}
|
||||
|
||||
$multiArray | Format-Wide {$_} -Column 6 -Force
|
||||
|
||||
$multiArray[2,2] # returns 33
|
||||
46
Task/Collections/PowerShell/collections-2.psh
Normal file
46
Task/Collections/PowerShell/collections-2.psh
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
# An empty Hash Table:
|
||||
$hash = @{}
|
||||
|
||||
# A Hash table populated with some values:
|
||||
$nfcCentralDivision = @{
|
||||
Packers = "Green Bay"
|
||||
Bears = "Chicago"
|
||||
Lions = "Detroit"
|
||||
}
|
||||
|
||||
# Add items to a Hash Table:
|
||||
$nfcCentralDivision.Add("Vikings","Minnesota")
|
||||
$nfcCentralDivision.Add("Buccaneers","Tampa Bay")
|
||||
|
||||
# Remove an item from a Hash Table:
|
||||
$nfcCentralDivision.Remove("Buccaneers")
|
||||
|
||||
# Searching for items
|
||||
$nfcCentralDivision.ContainsKey("Packers")
|
||||
$nfcCentralDivision.ContainsValue("Green Bay")
|
||||
|
||||
# A bad value...
|
||||
$hash1 = @{
|
||||
One = 1
|
||||
Two = 3
|
||||
}
|
||||
|
||||
# Edit an item in a Hash Table:
|
||||
$hash1.Set_Item("Two",2)
|
||||
|
||||
# Combine Hash Tables:
|
||||
|
||||
$hash2 = @{
|
||||
Three = 3
|
||||
Four = 4
|
||||
}
|
||||
|
||||
$hash1 + $hash2
|
||||
|
||||
# Using the ([ordered]) accelerator the items in the Hash Table retain the order in which they were input:
|
||||
$nfcCentralDivision = [ordered]@{
|
||||
Bears = "Chicago"
|
||||
Lions = "Detroit"
|
||||
Packers = "Green Bay"
|
||||
Vikings = "Minnesota"
|
||||
}
|
||||
9
Task/Collections/PowerShell/collections-3.psh
Normal file
9
Task/Collections/PowerShell/collections-3.psh
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
$list = New-Object -TypeName System.Collections.ArrayList -ArgumentList 1,2,3
|
||||
|
||||
# or...
|
||||
|
||||
$list = [System.Collections.ArrayList]@(1,2,3)
|
||||
|
||||
|
||||
$list.Add(4) | Out-Null
|
||||
$list.RemoveAt(2)
|
||||
4
Task/Collections/Ring/collections.ring
Normal file
4
Task/Collections/Ring/collections.ring
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
text = list(2)
|
||||
text[1] = "Hello "
|
||||
text[2] = "world!"
|
||||
see text[1] + text[2] + nl
|
||||
|
|
@ -1 +0,0 @@
|
|||
(append lst ...)
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
(display (append (list 1 2 3) (list 4 5 6)))
|
||||
(newline)
|
||||
|
|
@ -1 +0,0 @@
|
|||
(1 2 3 4 5 6)
|
||||
|
|
@ -12,5 +12,5 @@ const proc: main is func
|
|||
aHash @:= ["helium"] "noble gas";
|
||||
for aValue key aKey range aHash do
|
||||
writeln(aKey <& ": " <& aValue);
|
||||
end for;
|
||||
end for;a
|
||||
end func;
|
||||
|
|
|
|||
9
Task/Collections/Setl4/collections-1.setl4
Normal file
9
Task/Collections/Setl4/collections-1.setl4
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
set = new('set 5 10 15 20 25 25')
|
||||
add(set,30)
|
||||
show(set)
|
||||
|
||||
show.eval('member(set,5)')
|
||||
show.eval('member(set,6)')
|
||||
|
||||
show.eval("exists(set,'eq(this,10)')")
|
||||
show.eval("forall(set,'eq(this,40)')")
|
||||
4
Task/Collections/Setl4/collections-2.setl4
Normal file
4
Task/Collections/Setl4/collections-2.setl4
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
iter = new('iter 1 10 2')
|
||||
show(iter)
|
||||
show.eval("eq(set.size(iter),5)")
|
||||
show.eval('member(iter,5)')
|
||||
7
Task/Collections/Setl4/collections-3.setl4
Normal file
7
Task/Collections/Setl4/collections-3.setl4
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
map = new('map one:1 two:2 ten:10 forty:40 hundred:100 thousand:1000')
|
||||
show(map)
|
||||
|
||||
show.eval("eq(get(map,'one'),1)")
|
||||
show.eval("eq(get(map,'one'),6)")
|
||||
show.eval("exists(map,'eq(get(map,this),2)')")
|
||||
show.eval("forall(map,'eq(get(map,this),2)')")
|
||||
3
Task/Collections/VBA/collections.vba
Normal file
3
Task/Collections/VBA/collections.vba
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
Dim coll As New Collection
|
||||
coll.Add "apple"
|
||||
coll.Add "banana"
|
||||
10
Task/Collections/Zkl/collections.zkl
Normal file
10
Task/Collections/Zkl/collections.zkl
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
Lists: L(1,2,3).append(4); //-->L(1,2,3,4), mutable list
|
||||
Read only list: ROList(1,2,3).append(4); // creates two lists
|
||||
|
||||
Bit bucket: Data(0,Int,1,2,3) // three bytes
|
||||
The "Int" means treat contents as a byte stream
|
||||
Data(0,Int,"foo ","bar") //-->7 bytes
|
||||
Data(0,Int,"foo ").append("bar") //ditto
|
||||
Data(0,Int,"foo\n","bar").readln() //-->"foo\n"
|
||||
Data(0,String,"foo ","bar") //-->9 bytes (2 \0s)
|
||||
Data(0,String,"foo ").append("bar").readln() //-->"foo "
|
||||
Loading…
Add table
Add a link
Reference in a new issue