summaryrefslogtreecommitdiff
path: root/ipl/procs/typecode.icn
blob: 5ad036099065e5c4ef0b73a22ca3a842a06d39de (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
############################################################################
#
#	File:     typecode.icn
#
#	Subject:  Procedures to produce letter code for Icon type
#
#	Author:   Ralph E. Griswold
#
#	Date:     April 6, 1993
#
############################################################################
#
#   This file is in the public domain.
#
############################################################################
#
#  typecode(x) produces a one-letter string identifying the type of
#  its argument. In most cases, the code is the first (lowercase)
#  letter of the type, as "i" for the integer type. Structure types
#  are in uppercase, as "L" for the list type. All records have the
#  code "R".  The code "C" is used for the co-expression type to avoid
#  conflict for the "c" for the cset type. In the case of graphics, "w"
#  is produced for windows.
#
############################################################################

procedure typecode(x)
   local code
				# be careful of records and their constructors
   image(x) ? {
      if ="record constructor " then return "p"
      if ="record" then return "R"
      }

   code := type(x)

   if code == ("list" | "set" | "table" | "co-expression") then
      code := map(code,&lcase,&ucase)

   return code[1]
end