Another update from ingydotnet^djgoku

This commit is contained in:
Ingy döt Net 2015-11-18 06:14:39 +00:00
parent 91df62d461
commit 948b86eafa
7604 changed files with 108452 additions and 22726 deletions

View file

@ -1,3 +1,4 @@
#define system.
#define system'collections.
// --- Program ---
@ -6,8 +7,9 @@
[
// 1. Create
#var aMap := Dictionary new.
aMap set &key:"key" &value:"foox".
aMap set &key:"key2" &value:"foo2".
aMap set &key:"key" &value:"foo".
aMap@"key" := "foox".
aMap@"key" := "foo".
aMap@"key2":= "foo2".
aMap@"key3":= "foo3".
aMap@"key4":= "foo4".
].

View file

@ -0,0 +1,19 @@
defmodule RC do
def dict_create(dict_impl \\ Map) do
d = dict_impl.new #=> creates an empty Dict
d1 = Dict.put(d,:foo,1)
d2 = Dict.put(d1,:bar,2)
print_vals(d2)
print_vals(Dict.put(d2,:foo,3))
end
defp print_vals(d) do
IO.inspect d
Enum.each(d, fn {k,v} -> IO.puts "#{k}: #{v}" end)
end
end
IO.puts "< create Map.new >"
RC.dict_create
IO.puts "\n< create HashDict.new >"
RC.dict_create(HashDict)

View file

@ -2,4 +2,4 @@ import Data.Map
dict = fromList [("key1","val1"), ("key2","val2")]
ans = Data.Map.lookup "key2" dict -- evaluates to "val2"
ans = Data.Map.lookup "key2" dict -- evaluates to Just "val2"

View file

@ -1,13 +1,21 @@
var assoc = {};
assoc['foo'] = 'bar';
assoc['another-key'] = 3;
assoc.thirdKey = 'we can also do this!'; // dot notation can be used if the property name
// is a valid identifier
assoc[2] = 'the index here is the string "2"';
assoc[null] = 'this also works';
assoc[(function(){return 'expr';})()] = 'Can use expressions too';
// dot notation can be used if the property name is a valid identifier
assoc.thirdKey = 'we can also do this!';
assoc[2] = "the index here is the string '2'";
//using JavaScript's object literal notation
var assoc = {
foo: 'bar',
'another-key': 3 //the key can either be enclosed by quotes or not
};
//iterating keys
for (var key in assoc) {
// hasOwnProperty() method ensures the property isn't inherited
if (assoc.hasOwnProperty(key)) {
alert('key:"' + key + '", value:"' + assoc[key] + '"');
}

View file

@ -1,4 +1,22 @@
var assoc = {
foo: 'bar',
'another-key': 3 //the key can either be enclosed by quotes or not
};
var map = new Map(),
fn = function () {},
obj = {};
map.set(fn, 123);
map.set(obj, 'abc');
map.set('key', 'val');
map.set(3, x => x + x);
map.get(fn); //=> 123
map.get(function () {}); //=> undefined because not the same function
map.get(obj); //=> 'abc'
map.get({}); //=> undefined because not the same object
map.get('key'); //=> 'val'
map.get(3); //=> (x => x + x)
map.size; //=> 4
//iterating using ES6 for..of syntax
for (var key of map.keys()) {
console.log(key + ' => ' + map.get(key));
}

View file

@ -1,6 +1,6 @@
/* NetRexx */
options replace format comments java crossref savelog symbols
options replace format comments java crossref symbols
key0 = '0'
key1 = 'key0'

View file

@ -0,0 +1 @@
M = Map();

View file

@ -0,0 +1,6 @@
mapput(M, "key", "value");
mapput(M, 17, "different value");
mapput(M, "key2", Pi);
mapget(M, "key2") \\ returns Pi
mapisdefined(M, "key3") \\ returns 0
mapdelete(M, "key2");

View file

@ -1,11 +1,21 @@
$array = array();
$array = []; // Simpler form of array initialization
$array['foo'] = 'bar';
$array['bar'] = 'foo';
echo($array['foo']); // bar
echo($array['moo']); // Undefined index
//alternative (inline) way
// Alternative (inline) way
$array2 = array('fruit' => 'apple',
'price' => 12.96,
'colour' => 'green');
// Another alternative (simpler) way
$array2 = ['fruit' => 'apple',
'price' => 12.96,
'colour' => 'green'];
// Check if key exists in the associative array
echo(isset($array['foo'])); // Faster, but returns false if the value of the element is set to null
echo(array_key_exists('foo', $array)); // Slower, but returns true if the value of the element is null

View file

@ -0,0 +1,49 @@
*process source xref attributes or(!);
assocarr: Proc Options(main);
Dcl 1 aa,
2 an Bin Fixed(31) Init(0),
2 pairs(100),
3 key Char(10) Var,
3 val Char(10) Var;
Dcl hi Char(10) Value((high(10)));
Dcl i Bin Fixed(31);
Dcl k Char(10) Var;
Call aadd('1','spam');
Call aadd('2','eggs');
Call aadd('3','foo');
Call aadd('2','spam');
Call aadd('4','spam');
Put Skip(' ');
Put Edit('Iterate over keys')(Skip,a);
Do i=1 To an;
k=key(i);
Put Edit('>'!!k!!'< => >'!!aacc(k)!!'<')(Skip,a);
End;
aadd: Proc(k,v);
Dcl (k,v) Char(*) Var;
If aacc(k)^=hi Then
Put Edit('Key >',k,'< would be a duplicate, not added.')
(Skip,a,a,a);
Else Do;
an+=1;
key(an)=k;
val(an)=v;
Put Edit('added >'!!k!!'< -> '!!v!!'<')(Skip,a);
End;
End;
aacc: Proc(k) Returns(Char(10) Var);
Dcl k Char(*) Var;
Dcl v Char(10) Var;
Dcl i Bin Fixed(31);
Do i=1 To an;
If key(i)=k Then
Return(val(i));
End;
Return(hi);
End;
End;

View file

@ -0,0 +1,4 @@
my %hash{Any}; # same as %hash{*}
class C {};
my %cash{C};
%cash{C.new} = 1;