summaryrefslogtreecommitdiff
path: root/ipl/packs/skeem/skextra.icn
blob: fc6b8cfcf9def244389218b8a3d0d164b5e6b75f (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
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
############################################################################
#
#	Name:	skextra.icn
#
#	Title:	Scheme in Icon
#
#	Author: Bob Alexander
#
#	Date:	March 23, 1995
#
#	Description: see skeem.icn
#
############################################################################

#
# skeem -- Scheme in Icon
#
# Some additional stuff not in the standard
#

#
# Initialize
#
# List entries are described in skfun.icn.
#
procedure InitExtra()
   #
   # Functions
   #
   DefFunction([
      ADD1,
      ATOM_P,
      BREAK,0,
      BREAK_LEVEL,0,
      EVAL,1,2,
      QUIT,0,1,
      READ_LINE,0,1,
      RESUME,0,1,
      SUB1,
      TOP,0,
      TRACE,&null,
      UNTRACE,&null])
   #
   # Syntaxes
   #
   DefSyntax([
      DEFINE_MACRO,"twoOrMore",
      ITRACE,
      ITRACEOFF,0,
      ITRACEON,0,
      REPEAT,"oneOrMore",
      TRACE_ALL,0,
      UNLESS,"oneOrMore",
      WHEN,"oneOrMore"])
   return
end

procedure EVAL(ex,env)
   return Eval(ex,env)
end

procedure QUIT(exitCode)
   exit(exitCode)
end

procedure WHEN(test,body[])
   return if F ~=== (Eval(test) | fail)\1 then
      EvalSeq(LList!body) | fail
end

procedure UNLESS(test,body[])
   return if F === (Eval(test) | fail)\1 then
      EvalSeq(LList!body) | fail
end

procedure REPEAT(count,body[])
   local result
   body := LList!body
   every 1 to count do
      result := EvalSeq(body) | fail
   return result
end

procedure ATOM_P(arg)
   return (LLIsNotPair(arg),T) | F
end

procedure BREAK()
   local result
   BreakLevel +:= 1
   result := ReadEvalPrint((InputPortStack[1].file | &input)\1) | Failure
   BreakLevel -:= 1
   return Failure ~=== result
end

procedure BREAK_LEVEL()
   return BreakLevel
end

procedure RESUME(value)
   Resume := Value(\value | F)
   fail
end

procedure TOP()
   Resume := "top"
   fail
end

procedure TRACE(funcs[])
   local fn,result,element
   if *funcs = 0 then {
      result := LLNull
      every result := LLPair((!sort(TraceSet)).name,result)
      return LLInvert(result)
      }
   else every element := !funcs do {
      fn := Eval(element) | fail
      fn.traced := "true"
      insert(TraceSet,fn)
      return NIL
      }
end

procedure UNTRACE(funcs[])
   local fn,element
   if *funcs = 0 then {
      FTrace := &null
      every (!TraceSet).traced := &null
      }
   else every element := !funcs do {
      fn := Eval(element) | fail
      fn.traced := &null
      delete(TraceSet,fn)
      }
   return NIL
end

procedure ITRACEON()
   return (&trace := -1,T)
end

procedure ITRACEOFF()
   return (&trace := 0,F)
end

procedure ITRACE(expr)
   local value
   &trace := -1
   value := Eval(expr) | Failure
   &trace := 0
   return Failure ~=== value
end

procedure TRACE_ALL()
   return FTrace := T
end

procedure DEFINE_MACRO(arg)
   local sym,value
   return Error(DEFINE_MACRO,"Not implemented for now")
##    return DEFINE(arg,,Macro)
end

procedure ADD1(n)
   return n + 1
end

procedure SUB1(n)
   return n - 1
end

procedure READ_LINE(port)
   local f
   f := (\port | InputPortStack[1]).file
   return String(read(f)) | EOFObject
end