Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -1,5 +1,7 @@
|
|||
#define system.
|
||||
#define system'collections.
|
||||
#define system'routines.
|
||||
#define extensions.
|
||||
|
||||
// --- Program ---
|
||||
|
||||
|
|
@ -7,13 +9,12 @@
|
|||
[
|
||||
// 1. Create
|
||||
#var aMap := Dictionary new.
|
||||
aMap set &key:"key" &value:"foox".
|
||||
aMap set &key:"key" &value:"foo".
|
||||
aMap set &key:"key2" &value:"foo2".
|
||||
aMap set &key:"key3" &value:"foo3".
|
||||
aMap set &key:"key4" &value:"foo4".
|
||||
aMap@"key" := "foox".
|
||||
aMap@"key2":= "foo2".
|
||||
aMap@"key3":= "foo3".
|
||||
aMap@"key4":= "foo4".
|
||||
|
||||
// Enumerate
|
||||
control foreach:aMap &do: aKeyValue
|
||||
[ console write:(aKeyValue key) write:" : " writeLine:(aKeyValue value) ].
|
||||
aMap run &each: aKeyValue
|
||||
[ console writeLine:(aKeyValue key):" : ":aKeyValue ].
|
||||
].
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
defmodule RC do
|
||||
def test_iterate(dict_impl \\ Map) do
|
||||
d = dict_impl.new |> Dict.put(:foo,1) |> Dict.put(:bar,2)
|
||||
print_vals(d)
|
||||
end
|
||||
|
||||
defp print_vals(d) do
|
||||
IO.inspect d
|
||||
Enum.each(d, fn {k,v} -> IO.puts "#{k}: #{v}" end)
|
||||
Enum.each(Dict.keys(d), fn key -> IO.inspect key end)
|
||||
Enum.each(Dict.values(d), fn value -> IO.inspect value end)
|
||||
end
|
||||
end
|
||||
|
||||
IO.puts "< iterate Map >"
|
||||
RC.test_iterate
|
||||
IO.puts "\n< iterate HashDict >"
|
||||
RC.test_iterate(HashDict)
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
var myhash = {}; //a new, empty object
|
||||
myhash["hello"] = 3;
|
||||
myhash.world = 6; //obj.name is equivalent to obj["name"] for certain values of name
|
||||
myhash["!"] = 9;
|
||||
|
||||
//iterate using for..in loop
|
||||
for (var key in myhash) {
|
||||
//ensure key is in object and not in prototype
|
||||
if (myhash.hasOwnProperty(key)) {
|
||||
console.log("Key is: " + key + '. Value is: ' + myhash[key]);
|
||||
}
|
||||
}
|
||||
|
||||
//iterate using ES5.1 Object.keys() and Array.prototype.Map()
|
||||
var keys = Object.keys(); //get Array of object keys (doesn't get prototype keys)
|
||||
keys.map(function (key) {
|
||||
console.log("Key is: " + key + '. Value is: ' + myhash[key]);
|
||||
});
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/* NetRexx */
|
||||
options replace format comments java crossref savelog symbols
|
||||
options replace format comments java crossref symbols
|
||||
|
||||
surname = 'Unknown' -- default value
|
||||
surname['Fred'] = 'Bloggs'
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
keys = Vec(M);
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
for(i=1,#keys,
|
||||
print(keys[i]," ",mapget(M,keys[i]))
|
||||
)
|
||||
|
|
@ -1,16 +1,17 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
fn main() {
|
||||
let mut squares = HashMap::new();
|
||||
squares.insert("one", 1i32);
|
||||
squares.insert("two", 4);
|
||||
squares.insert("three", 9);
|
||||
for key in squares.keys() {
|
||||
println!("Key {}", key);
|
||||
}
|
||||
for value in squares.values() {
|
||||
println!("Value {}", value);
|
||||
}
|
||||
for (key, value) in squares.iter() {
|
||||
println!("{} => {}", key, value);
|
||||
}
|
||||
let mut squares = HashMap::new();
|
||||
squares.insert("one", 1);
|
||||
squares.insert("two", 4);
|
||||
squares.insert("three", 9);
|
||||
for key in squares.keys() {
|
||||
println!("Key {}", key);
|
||||
}
|
||||
for value in squares.values() {
|
||||
println!("Value {}", value);
|
||||
}
|
||||
for (key, value) in squares.iter() {
|
||||
println!("{} => {}", key, value);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
@(do (defvar *h* (make-hash nil nil nil))
|
||||
(each ((k '(a b c))
|
||||
(v '(1 2 3)))
|
||||
(set [*h* k nil] v))
|
||||
(dohash (k v *h*)
|
||||
(format t "~a -> ~a\n" k v))))
|
||||
(defvarl h (hash))
|
||||
|
||||
(each ((k '(a b c))
|
||||
(v '(1 2 3)))
|
||||
(set [h k] v))
|
||||
|
||||
(dohash (k v h)
|
||||
(put-line `@k -> @v`))
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
'instantiate the dictionary object
|
||||
Set dict = CreateObject("Scripting.Dictionary")
|
||||
|
||||
'populate the dictionary or hash table
|
||||
dict.Add 1,"larry"
|
||||
dict.Add 2,"curly"
|
||||
dict.Add 3,"moe"
|
||||
|
||||
'iterate key and value pairs
|
||||
For Each key In dict.Keys
|
||||
WScript.StdOut.WriteLine key & " - " & dict.Item(key)
|
||||
Next
|
||||
Loading…
Add table
Add a link
Reference in a new issue