summaryrefslogtreecommitdiff
path: root/ipl/procs/procname.icn
blob: c929b63ad329ea5da402f6e583a92dbe0138bd5c (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
49
50
51
52
############################################################################
#
#	File:     procname.icn
#
#	Subject:  Procedure to produce name of procedure
#
#	Author:   Ralph E. Griswold
#
#	Date:     May 2, 2001
#
############################################################################
#
#   This file is in the public domain.
#
############################################################################
#
#  procname(p, x) produces the name of a procedure from a procedure value.
#  Here, the term "procedure" includes functions, operators, and
#  record constructors.
#
#  If x is null, the result is derived from image() is a relatively
#  straightforward way.  In the case of operators, the number of
#  arguments is appended to the operator symbol.
#
#  If x is nonnull, the result is put in a form that resembles an Icon
#  expression.
#
#  procname() fails if p is not of type procedure.
#
############################################################################

procedure procname(p, x)
   local result

   image(p) ? {
      =("function " | "procedure " | "record constructor ")
      if /x then return if any(&letters) then tab(0) else tab(0) || args(p)
      else result := tab(0)
      if any(&letters, result) then return result || "()"
      else return case args(p) of {
         0:  result
         1:  result || "e"
         2:  if result == "[]" then "e1[e2]" else "e1 " || result || " e2"
         3:  case result of {
             "...":   "e1 to e2 by e3"
             "[:]":   "e1[e2:e3]"
             default: "<<< ... " || result || "... >>>"
             }
         }
      }

end