A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
|
|
@ -0,0 +1,6 @@
|
|||
H{ { "one" 1 } { "two" 2 } }
|
||||
{ [ "one" swap at . ]
|
||||
[ 2 swap value-at . ]
|
||||
[ "three" swap at . ]
|
||||
[ [ 3 "three" ] dip set-at ]
|
||||
[ "three" swap at . ] } cleave
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
class Main
|
||||
{
|
||||
public static Void main ()
|
||||
{
|
||||
// create a map which maps Ints to Strs, with given key-value pairs
|
||||
Int:Str map := [1:"alpha", 2:"beta", 3:"gamma"]
|
||||
|
||||
// create an empty map
|
||||
Map map2 := [:]
|
||||
// now add some numbers mapped to their doubles
|
||||
10.times |Int i|
|
||||
{
|
||||
map2[i] = 2*i
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
map = [:]
|
||||
map[7] = 7
|
||||
map['foo'] = 'foovalue'
|
||||
map.put('bar', 'barvalue')
|
||||
map.moo = 'moovalue'
|
||||
|
||||
assert 7 == map[7]
|
||||
assert 'foovalue' == map.foo
|
||||
assert 'barvalue' == map['bar']
|
||||
assert 'moovalue' == map.get('moo')
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
map = [7:7, foo:'foovalue', bar:'barvalue', moo:'moovalue']
|
||||
|
||||
assert 7 == map[7]
|
||||
assert 'foovalue' == map.foo
|
||||
assert 'barvalue' == map['bar']
|
||||
assert 'moovalue' == map.get('moo')
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
procedure main()
|
||||
local t
|
||||
t := table()
|
||||
t["foo"] := "bar"
|
||||
write(t["foo"])
|
||||
end
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
Hash Bar is a room.
|
||||
|
||||
Connection relates various texts to one number. The verb to be connected to implies the connection relation.
|
||||
|
||||
"foo" is connected to 12.
|
||||
"bar" is connected to 34.
|
||||
"baz" is connected to 56.
|
||||
|
||||
When play begins:
|
||||
[change values]
|
||||
now "bleck" is connected to 78;
|
||||
[check values]
|
||||
if "foo" is connected to 12, say "good.";
|
||||
if "bar" is not connected to 56, say "good.";
|
||||
[retrieve values]
|
||||
let V be the number that "baz" relates to by the connection relation;
|
||||
say "'baz' => [V].";
|
||||
end the story.
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
Hash Bar is a room.
|
||||
|
||||
When play begins:
|
||||
let R be a various-to-one relation of texts to numbers;
|
||||
[initialize the relation]
|
||||
now R relates "foo" to 12;
|
||||
now R relates "bar" to 34;
|
||||
now R relates "baz" to 56;
|
||||
[check values]
|
||||
if R relates "foo" to 12, say "good.";
|
||||
if R does not relate "bar" to 56, say "good.";
|
||||
[retrieve values]
|
||||
let V be the number that "baz" relates to by R;
|
||||
say "'baz' => [V].";
|
||||
end the story.
|
||||
|
|
@ -0,0 +1 @@
|
|||
{a: "a", b: "b"}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
coclass 'assocArray'
|
||||
encode=: 'z', (a.{~;48 65 97(+ i.)&.>10 26 26) {~ 62x #.inv 256x #. a.&i.
|
||||
get=: ".@encode
|
||||
has=: 0 <: nc@<@encode
|
||||
set=:4 :'(encode x)=:y'
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
example=: conew 'assocArray'
|
||||
'foo' set__example 1 2 3
|
||||
1 2 3
|
||||
'bar' set__example 4 5 6
|
||||
4 5 6
|
||||
get__example 'foo'
|
||||
1 2 3
|
||||
has__example 'foo'
|
||||
1
|
||||
bletch__example=: 7 8 9
|
||||
get__example 'bletch'
|
||||
7 8 9
|
||||
codestroy__example''
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
/ creating an dictionary
|
||||
d1:.((`foo;1); (`bar;2); (`baz;3))
|
||||
|
||||
/ extracting a value
|
||||
d1[`bar]
|
||||
2
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
d2: .() / create empty dictionary
|
||||
d2[`"zero"]:0
|
||||
d2[`"one"]:1
|
||||
d2[`"two"]:2
|
||||
|
||||
d2
|
||||
.((`zero;0;)
|
||||
(`one;1;)
|
||||
(`two;2;))
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
!d2 / the keys
|
||||
`zero `one `two
|
||||
|
||||
d2[] / the values
|
||||
0 1 2
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
: dip swap '_ set execute _ ; : nip swap drop ;
|
||||
: first 0 extract nip ; : second 1 extract nip ;
|
||||
|
||||
: assoc-in swap keys eq ;
|
||||
: assoc-index' over keys swap eq [1] index collapse ;
|
||||
: at swap assoc-index' subscript collapse second ;
|
||||
: delete-at swap assoc-index' first remove ;
|
||||
: keys 1 transpose first ;
|
||||
: set-at
|
||||
over 'dup dip assoc-in '+ reduce if 'dup dip delete-at then
|
||||
"swap 2 compress 1 compress" dip swap append ;
|
||||
|
||||
[['foo 5]]
|
||||
10 'bar rot set-at
|
||||
'bar over at .
|
||||
'hello 'bar rot set-at
|
||||
20 'baz rot set-at .
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
data "red", "255 50 50", "green", "50 255 50", "blue", "50 50 255"
|
||||
data "my fave", "220 120 120", "black", "0 0 0"
|
||||
|
||||
myAssocList$ =""
|
||||
|
||||
for i =1 to 5
|
||||
read k$
|
||||
read dat$
|
||||
call sl.Set myAssocList$, k$, dat$
|
||||
next i
|
||||
|
||||
print " Key 'green' is associated with data item "; sl.Get$( myAssocList$, "green")
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
pprop "animals "cat 5
|
||||
pprop "animals "dog 4
|
||||
pprop "animals "mouse 11
|
||||
print gprop "animals "cat ; 5
|
||||
remprop "animals "dog
|
||||
show plist "animals ; [mouse 11 cat 5]
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
> T := table( [ (2,3) = 4, "foo" = 1, sin(x) = cos(x) ] );
|
||||
T := table(["foo" = 1, sin(x) = cos(x), (2, 3) = 4])
|
||||
|
||||
> T[2,3];
|
||||
4
|
||||
|
||||
> T[sin(x)];
|
||||
cos(x)
|
||||
|
||||
> T["foo"];
|
||||
1
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
> T[ "bar" ] := 2;
|
||||
T["bar"] := 2
|
||||
|
||||
> T[ "bar" ];
|
||||
2
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
> T[ "foo" ] := evaln( T[ "foo" ] );
|
||||
T["foo"] := T["foo"]
|
||||
|
||||
> T[ "foo" ];
|
||||
T["foo"]
|
||||
|
|
@ -0,0 +1 @@
|
|||
a[2] = "string"; a["sometext"] = 23;
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
/* No need to declare anything, undeclared arrays are hashed */
|
||||
|
||||
h[1]: 6;
|
||||
h[9]: 2;
|
||||
|
||||
arrayinfo(h);
|
||||
[hashed, 1, [1], [9]]
|
||||
Loading…
Add table
Add a link
Reference in a new issue