/usr/share/axiom-20170501/src/algebra/TBAGG.spad is in axiom-source 20170501-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | )abbrev category TBAGG TableAggregate
++ Author: Michael Monagan, Stephen Watt;
++ revised by Manuel Bronstein and Richard Jenks
++ Date Created: August 87 through August 88
++ Date Last Updated: April 1991
++ Description:
++ A table aggregate is a model of a table, that is, a discrete many-to-one
++ mapping from keys to entries.
TableAggregate(Key, Entry) : Category == SIG where
Key : SetCategory
Entry : SetCategory
SIG ==> Join(KeyedDictionary(Key,Entry),IndexedAggregate(Key,Entry)) with
setelt : (%,Key,Entry) -> Entry
++ setelt(t,k,e) (also written \axiom{t.k := e}) is equivalent
++ to \axiom{(insert([k,e],t); e)}.
table : () -> %
++table()$T creates an empty table of type T.
++
++X Data:=Record(age:Integer,gender:String)
++X a1:AssociationList(String,Data):=table()
++X a1."tim":=[55,"male"]$Data
table : List Record(key:Key,entry:Entry) -> %
++ table([x,y,...,z]) creates a table consisting of entries
++ \axiom{x,y,...,z}.
map : ((Entry, Entry) -> Entry, %, %) -> %
++ map(fn,t1,t2) creates a new table t from given tables t1 and t2 with
++ elements fn(x,y) where x and y are corresponding elements from t1
++ and t2 respectively.
add
table() == empty()
table l == dictionary l
insert_!(p, t) == (t(p.key) := p.entry; t)
indices t == keys t
coerce(t:%):OutputForm ==
prefix("table"::OutputForm,
[k::OutputForm = (t.k)::OutputForm for k in keys t])
elt(t, k) ==
(r := search(k, t)) case Entry => r::Entry
error "key not in table"
elt(t, k, e) ==
(r := search(k, t)) case Entry => r::Entry
e
map_!(f, t) ==
for k in keys t repeat t.k := f t.k
t
map(f:(Entry, Entry) -> Entry, s:%, t:%) ==
z := table()
for k in keys s | key?(k, t) repeat z.k := f(s.k, t.k)
z
if % has finiteAggregate then
parts(t:%):List Record(key:Key,entry:Entry) ==
[[k, t.k] for k in keys t]
parts(t:%):List Entry == [t.k for k in keys t]
entries(t:%):List Entry == parts(t)
s:% = t:% ==
eq?(s,t) => true
#s ^= #t => false
for k in keys s repeat
(e := search(k, t)) _
case "failed" or (e::Entry) ^= s.k => return false
true
map(f: Record(key:Key,entry:Entry)->Record(key:Key,entry:Entry),t:%):%==
z := table()
for k in keys t repeat
ke: Record(key:Key,entry:Entry) := f [k, t.k]
z ke.key := ke.entry
z
map_!(f:Record(key:Key,entry:Entry)->Record(key:Key,entry:Entry),t:%):%_
==
lke: List Record(key:Key,entry:Entry) := nil()
for k in keys t repeat
lke := cons(f [k, remove_!(k,t)::Entry], lke)
for ke in lke repeat
t ke.key := ke.entry
t
inspect(t: %): Record(key:Key,entry:Entry) ==
ks := keys t
empty? ks => error "Cannot extract from an empty aggregate"
[first ks, t first ks]
find(f: Record(key:Key,entry:Entry)->Boolean, t:%):_
Union(Record(key:Key,entry:Entry), "failed") ==
for ke in parts(t)@List(Record(key:Key,entry:Entry)) _
repeat if f ke then return ke
"failed"
index?(k: Key, t: %): Boolean ==
search(k,t) case Entry
remove_!(x:Record(key:Key,entry:Entry), t:%) ==
if member?(x, t) then remove_!(x.key, t)
t
extract_!(t: %): Record(key:Key,entry:Entry) ==
k: Record(key:Key,entry:Entry) := inspect t
remove_!(k.key, t)
k
any?(f: Entry->Boolean, t: %): Boolean ==
for k in keys t | f t k repeat return true
false
every?(f: Entry->Boolean, t: %): Boolean ==
for k in keys t | not f t k repeat return false
true
count(f: Entry->Boolean, t: %): NonNegativeInteger ==
tally: NonNegativeInteger := 0
for k in keys t | f t k repeat tally := tally + 1
tally
|