This commit is contained in:
Ingy döt Net 2013-04-10 21:29:02 -07:00
parent 764da6cbbb
commit db842d013d
19005 changed files with 197040 additions and 7 deletions

View file

@ -0,0 +1 @@
H{ { "hi" "there" } { "a" "b" } } [ ": " glue print ] assoc-each

View file

@ -0,0 +1,22 @@
class Main
{
public static Void main ()
{
Int:Str map := [1:"alpha", 2:"beta", 3:"gamma"]
map.keys.each |Int key|
{
echo ("Key is: $key")
}
map.vals.each |Str value|
{
echo ("Value is: $value")
}
map.each |Str value, Int key|
{
echo ("Key $key maps to $value")
}
}
}

View file

@ -0,0 +1,12 @@
def map = [lastName: "Anderson", firstName: "Thomas", nickname: "Neo", age: 24, address: "everywhere"]
println "Entries:"
map.each { println it }
println()
println "Keys:"
map.keySet().each { println it }
println()
println "Values:"
map.values().each { println it }

View file

@ -0,0 +1,15 @@
procedure main()
t := table()
every t[a := !"ABCDE"] := map(a)
every pair := !sort(t) do
write("\t",pair[1]," -> ",pair[2])
writes("Keys:")
every writes(" ",key(t))
write()
writes("Values:")
every writes(" ",!t)
write()
end

View file

@ -0,0 +1 @@
nl__example 0

View file

@ -0,0 +1 @@
get__example each nl__example 0

View file

@ -0,0 +1 @@
(,&< get__example) each nl__example 0

View file

@ -0,0 +1 @@
d: .((`"hello";1); (`"world";2);(`"!";3))

View file

@ -0,0 +1,7 @@
!d
`hello `world `"!"
$!d / convert keys (symbols) as strings
("hello"
"world"
,"!")

View file

@ -0,0 +1,4 @@
`0:{,/$x,": ",d[x]}'!d
hello: 1
world: 2
!: 3

View file

@ -0,0 +1,5 @@
d[]
1 2 3
{x+1}'d[]
2 3 4

View file

@ -0,0 +1,4 @@
: first 0 extract nip ; : second 1 extract nip ; : nip swap drop ;
: say(*) dup first " => " 2 compress "" join . second . ;
[['foo 5] ['bar 10] ['baz 20]] 'say apply drop

View file

@ -0,0 +1,23 @@
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
keys$ = "" ' List to hold the keys in myList$.
keys = 0
keys = sl.Keys( myAssocList$, keys$)
print " Number of key-data pairs ="; keys
For i = 1 To keys
keyName$ = sl.Get$( keys$, Str$( i))
Print " Key "; i; ":", keyName$, "Data: ", sl.Get$( myAssocList$, keyName$)
Next i
end

View file

@ -0,0 +1,35 @@
divert(-1)
define(`for',
`ifelse($#,0,``$0'',
`ifelse(eval($2<=$3),1,
`pushdef(`$1',$2)$4`'popdef(`$1')$0(`$1',incr($2),$3,`$4')')')')
define(`new',`define(`$1[size]key',0)')
define(`asize',`defn(`$1[size]key')')
define(`aget',`defn(`$1[$2]')')
define(`akget',`defn(`$1[$2]key')')
define(`avget',`aget($1,akget($1,$2))')
define(`aset',
`ifdef($1[$2],
`',
`define(`$1[size]key',incr(asize(`$1')))`'define($1[asize(`$1')]key,$2)')`'define($1[$2],$3)')
define(`dquote', ``$@'')
define(`akeyvalue',`dquote(akget($1,$2),aget($1,akget($1,$2)))')
define(`akey',`dquote(akget($1,$2))')
define(`avalue',`dquote(aget($1,akget($1,$2)))')
divert
new(`a')
aset(`a',`wow',5)
aset(`a',`wow',flame)
aset(`a',`bow',7)
key-value pairs
for(`x',1,asize(`a'),
`akeyvalue(`a',x)
')
keys
for(`x',1,asize(`a'),
`akey(`a',x)
')
values
for(`x',1,asize(`a'),
`avalue(`a',x)
')

View file

@ -0,0 +1,21 @@
> T := table( [ "a" = 1, "b" = 2, ("c","d") = 3 ] ):
> for i in indices( T ) do print( i, T[ op( i ) ] ) end:
["a"], 1
["c", "d"], 3
["b"], 2
> for i in indices( T ) do print( op( i ) ) end:
"a"
"c", "d"
"b"
> for i in entries( T ) do print( i) end:
[1]
[3]
[2]

View file

@ -0,0 +1,8 @@
keys=DownValues[#,Sort->False][[All,1,1,1]]&;
hashes=#/@keys[#]&;
a[2]="string";a["sometext"]=23;
keys[a]
->{2,sometext}
hashes[a]
->{string,23}