summaryrefslogtreecommitdiff
path: root/ipl/procs/hetero.icn
blob: 85a6609846c2852838be70c28a3e25cd1b7798a8 (plain)
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
############################################################################
#
#	File:     hetero.icn
#
#	Subject:  Procedures to test structure typing
#
#	Author:   Ralph E. Griswold
#
#	Date:     April 19, 1996
#
############################################################################
#
#   This file is in the public domain.
#
############################################################################
#
#
#
############################################################################

procedure stypes(X, ref)		#: types of structure elements
   local op, types, t, k

   op := proc("!", 1)
   t := type(X)
   op := if (t == "table") & (ref === 1) then "key" 

   if (t == "table") & (ref === 2) then {
      types := set()
      every k := key(X) do
         insert(types, type(k) || ":" ||  type(X[k]))
      return sort(types)
      }

   else if t == ("list" | "record" | "table" | "set") then {
      types := set()
      every insert(types, type(op(X)))
      return sort(types)
      }
   else stop("*** invalid type to stypes()")

end

procedure homogeneous(X, ref)

   if *stypes(X, ref) = 1 then return else fail

end