summary refs log tree commit diff stats
path: root/compiler/trees.nim
blob: 05c060595373612ebd3050814b74630a0df8c824 (plain) (blame)
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#
#
#           The Nim Compiler
#        (c) Copyright 2012 Andreas Rumpf
#
#    See the file "copying.txt", included in this
#    distribution, for details about the copyright.
#

# tree helper routines

import
  ast, wordrecg, idents

proc cyclicTreeAux(n: PNode, visited: var seq[PNode]): bool =
  if n == nil: return
  for v in visited:
    if v == n: return true
  if not (n.kind in {nkEmpty..nkNilLit}):
    visited.add(n)
    for nSon in n.sons:
      if cyclicTreeAux(nSon, visited): return true
    discard visited.pop()

proc cyclicTree*(n: PNode): bool =
  var visited: seq[PNode] = @[]
  cyclicTreeAux(n, visited)

proc sameFloatIgnoreNan(a, b: BiggestFloat): bool {.inline.} =
  ## ignores NaN semantics, but ensures 0.0 == -0.0, see #13730
  cast[uint64](a) == cast[uint64](b) or a == b

proc exprStructuralEquivalent*(a, b: PNode; strictSymEquality=false): bool =
  if a == b:
    result = true
  elif (a != nil) and (b != nil) and (a.kind == b.kind):
    case a.kind
    of nkSym:
      if strictSymEquality:
        result = a.sym == b.sym
      else:
        # don't go nuts here: same symbol as string is enough:
        result = a.sym.name.id == b.sym.name.id
    of nkIdent: result = a.ident.id == b.ident.id
    of nkCharLit..nkUInt64Lit: result = a.intVal == b.intVal
    of nkFloatLit..nkFloat64Lit: result = sameFloatIgnoreNan(a.floatVal, b.floatVal)
    of nkStrLit..nkTripleStrLit: result = a.strVal == b.strVal
    of nkCommentStmt: result = a.comment == b.comment
    of nkEmpty, nkNilLit, nkType: result = true
    else:
      if a.len == b.len:
        for i in 0..<a.len:
          if not exprStructuralEquivalent(a[i], b[i],
                                          strictSymEquality): return
        result = true

proc sameTree*(a, b: PNode): bool =
  if a == b:
    result = true
  elif a != nil and b != nil and a.kind == b.kind:
    if a.flags != b.flags: return
    if a.info.line != b.info.line: return
    if a.info.col != b.info.col:
      return                  #if a.info.fileIndex <> b.info.fileIndex then exit;
    case a.kind
    of nkSym:
      # don't go nuts here: same symbol as string is enough:
      result = a.sym.name.id == b.sym.name.id
    of nkIdent: result = a.ident.id == b.ident.id
    of nkCharLit..nkUInt64Lit: result = a.intVal == b.intVal
    of nkFloatLit..nkFloat64Lit: result = sameFloatIgnoreNan(a.floatVal, b.floatVal)
    of nkStrLit..nkTripleStrLit: result = a.strVal == b.strVal
    of nkEmpty, nkNilLit, nkType: result = true
    else:
      if a.len == b.len:
        for i in 0..<a.len:
          if not sameTree(a[i], b[i]): return
        result = true

proc getMagic*(op: PNode): TMagic =
  if op == nil: return mNone
  case op.kind
  of nkCallKinds:
    case op[0].kind
    of nkSym: result = op[0].sym.magic
    else: result = mNone
  else: result = mNone

proc isConstExpr*(n: PNode): bool =
  const atomKinds = {nkCharLit..nkNilLit} # Char, Int, UInt, Str, Float and Nil literals
  n.kind in atomKinds or nfAllConst in n.flags

proc isCaseObj*(n: PNode): bool =
  if n.kind == nkRecCase: return true
  for i in 0..<n.safeLen:
    if n[i].isCaseObj: return true

proc isDeepConstExpr*(n: PNode; preventInheritance = false): bool =
  case n.kind
  of nkCharLit..nkNilLit:
    result = true
  of nkExprEqExpr, nkExprColonExpr, nkHiddenStdConv, nkHiddenSubConv:
    result = isDeepConstExpr(n[1], preventInheritance)
  of nkCurly, nkBracket, nkPar, nkTupleConstr, nkObjConstr, nkClosure, nkRange:
    for i in ord(n.kind == nkObjConstr)..<n.len:
      if not isDeepConstExpr(n[i], preventInheritance): return false
    if n.typ.isNil: result = true
    else:
      let t = n.typ.skipTypes({tyGenericInst, tyDistinct, tyAlias, tySink, tyOwned})
      if t.kind in {tyRef, tyPtr} or tfUnion in t.flags: return false
      if t.kind == tyObject:
        if preventInheritance and t[0] != nil:
          result = false
        elif isCaseObj(t.n):
          result = false
        else:
          result = true
      else:
        result = true
  else: discard

proc isRange*(n: PNode): bool {.inline.} =
  if n.kind in nkCallKinds:
    let callee = n[0]
    if (callee.kind == nkIdent and callee.ident.id == ord(wDotDot)) or
       (callee.kind == nkSym and callee.sym.name.id == ord(wDotDot)) or
       (callee.kind in {nkClosedSymChoice, nkOpenSymChoice} and
        callee[1].sym.name.id == ord(wDotDot)):
      result = true

proc whichPragma*(n: PNode): TSpecialWord =
  let key = if n.kind in nkPragmaCallKinds and n.len > 0: n[0] else: n
  case key.kind
  of nkIdent: result = whichKeyword(key.ident)
  of nkSym: result = whichKeyword(key.sym.name)
  of nkCast: result = wCast
  of nkClosedSymChoice, nkOpenSymChoice:
    result = whichPragma(key[0])
  else: result = wInvalid

proc isNoSideEffectPragma*(n: PNode): bool =
  var k = whichPragma(n)
  if k == wCast:
    k = whichPragma(n[1])
  result = k == wNoSideEffect

proc findPragma*(n: PNode, which: TSpecialWord): PNode =
  if n.kind == nkPragma:
    for son in n:
      if whichPragma(son) == which:
        return son

proc effectSpec*(n: PNode, effectType: TSpecialWord): PNode =
  for i in 0..<n.len:
    var it = n[i]
    if it.kind == nkExprColonExpr and whichPragma(it) == effectType:
      result = it[1]
      if result.kind notin {nkCurly, nkBracket}:
        result = newNodeI(nkCurly, result.info)
        result.add(it[1])
      return

proc propSpec*(n: PNode, effectType: TSpecialWord): PNode =
  for i in 0..<n.len:
    var it = n[i]
    if it.kind == nkExprColonExpr and whichPragma(it) == effectType:
      return it[1]

proc unnestStmts(n, result: PNode) =
  if n.kind == nkStmtList:
    for x in items(n): unnestStmts(x, result)
  elif n.kind notin {nkCommentStmt, nkNilLit}:
    result.add(n)

proc flattenStmts*(n: PNode): PNode =
  result = newNodeI(nkStmtList, n.info)
  unnestStmts(n, result)
  if result.len == 1:
    result = result[0]

proc extractRange*(k: TNodeKind, n: PNode, a, b: int): PNode =
  result = newNodeI(k, n.info, b-a+1)
  for i in 0..b-a: result[i] = n[i+a]

proc isTrue*(n: PNode): bool =
  n.kind == nkSym and n.sym.kind == skEnumField and n.sym.position != 0 or
    n.kind == nkIntLit and n.intVal != 0

proc getRoot*(n: PNode): PSym =
  ## ``getRoot`` takes a *path* ``n``. A path is an lvalue expression
  ## like ``obj.x[i].y``. The *root* of a path is the symbol that can be
  ## determined as the owner; ``obj`` in the example.
  case n.kind
  of nkSym:
    if n.sym.kind in {skVar, skResult, skTemp, skLet, skForVar, skParam}:
      result = n.sym
  of nkDotExpr, nkBracketExpr, nkHiddenDeref, nkDerefExpr,
      nkObjUpConv, nkObjDownConv, nkCheckedFieldExpr, nkHiddenAddr, nkAddr:
    result = getRoot(n[0])
  of nkHiddenStdConv, nkHiddenSubConv, nkConv:
    result = getRoot(n[1])
  of nkCallKinds:
    if getMagic(n) == mSlice: result = getRoot(n[1])
  else: discard

proc stupidStmtListExpr*(n: PNode): bool =
  for i in 0..<n.len-1:
    if n[i].kind notin {nkEmpty, nkCommentStmt}: return false
  result = true

proc dontInlineConstant*(orig, cnst: PNode): bool {.inline.} =
  # symbols that expand to a complex constant (array, etc.) should not be
  # inlined, unless it's the empty array:
  result = orig.kind != cnst.kind and
           cnst.kind in {nkCurly, nkPar, nkTupleConstr, nkBracket, nkObjConstr} and
           cnst.len > ord(cnst.kind == nkObjConstr)
ot;../v1ch15/debug.html">Ch15</A> <BR> conversational front end <A HREF="../v1ch12/playfair.html">Ch12</A> <BR> coordinates <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> coordinates, Cartesian <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> <CODE>count</CODE> <A HREF="../v1ch2/proced.html">Ch2</A> <BR> Courant, Richard <A HREF="../v1ch14/pour.html">Ch14</A> <BR> <CODE>cs</CODE> <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> <CODE>ct</CODE> <A HREF="../v1ch1/explor.html">Ch1</A> <P><A NAME="D"></A> <BR> Dahl, O. J. <A HREF="../v1ch13/plan.html">Ch13</A> <BR> Dao, Khang <A HREF="../v1ch0/ack.html">Ack</A> <BR> data redundancy <A HREF="../v1ch12/playfair.html">Ch12</A> <BR> data representation <A HREF="../v1ch6/ttt.html">Ch6</A> , <A HREF="../v1ch14/pour.html">Ch14</A> <BR> data structure <A HREF="../v1ch6/ttt.html">Ch6</A> <BR> data type, abstract <A HREF="../v1ch14/pour.html">Ch14</A> <BR> datum <A HREF="../v1ch2/proced.html">Ch2</A> <BR> Davidson, Larry <A HREF="../v1ch0/ack.html">Ack</A> <BR> Davis, Jim <A HREF="../v1ch0/ack.html">Ack</A> <BR> debugging <A HREF="../v1ch13/plan.html">Ch13</A> , <A HREF="../v1ch15/debug.html">Ch15</A> <BR> defensive programming <A HREF="../v1ch15/debug.html">Ch15</A> <BR> defining a procedure <A HREF="../v1ch2/proced.html">Ch2</A> <BR> depth-first search <A HREF="../v1ch14/pour.html">Ch14</A> <BR> Descartes, Ren&eacute; <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> describe a procedure, how to <A HREF="../v1ch2/proced.html">Ch2</A> <BR> Deutsch, Freeman <A HREF="../v1ch0/ack.html">Ack</A> <BR> diagram, plumbing <A HREF="../v1ch2/proced.html">Ch2</A> <BR> Dijkstra, Edsger <A HREF="../v1ch13/plan.html">Ch13</A> <BR> Diophantine equation <A HREF="../v1ch14/pour.html">Ch14</A> <BR> domain <A HREF="../v1ch5/hof.html">Ch5</A> <BR> dots <A HREF="../v1ch3/variab.html">Ch3</A> <BR> dynamic scope <A HREF="../v1ch3/variab.html">Ch3</A> <P><A NAME="E"></A> <BR> <CODE>edit</CODE> <A HREF="../v1ch2/proced.html">Ch2</A> <BR> editor <A HREF="../v1ch2/proced.html">Ch2</A> <BR> effect <A HREF="../v1ch2/proced.html">Ch2</A> <BR> efficiency <A HREF="../v1ch14/pour.html">Ch14</A> <BR> elves <A HREF="../v1ch3/variab.html">Ch3</A> , <A HREF="../v1ch9/recur3.html">Ch9</A> <BR> Elvish <A HREF="../v1ch11/recops.html">Ch11</A> <BR> empty list <A HREF="../v1ch2/proced.html">Ch2</A> <BR> empty word <A HREF="../v1ch2/proced.html">Ch2</A> <BR> <CODE>emptyp</CODE> <A HREF="../v1ch4/predic.html">Ch4</A> <BR> <CODE>end</CODE> <A HREF="../v1ch2/proced.html">Ch2</A> <BR> environment, programming <A HREF="../v1ch1/explor.html">Ch1</A> <BR> equal sign <A HREF="../v1ch4/predic.html">Ch4</A> <BR> <CODE>equalp</CODE> <A HREF="../v1ch4/predic.html">Ch4</A> <BR> equation, algebraic <A HREF="../v1ch14/pour.html">Ch14</A> <BR> equation, Diophantine <A HREF="../v1ch14/pour.html">Ch14</A> <BR> error message <A HREF="../v1ch2/proced.html">Ch2</A> , <A HREF="../v1ch15/debug.html">Ch15</A> <BR> evaluation <A HREF="../v1ch2/proced.html">Ch2</A> <BR> expression <A HREF="../v1ch2/proced.html">Ch2</A> <BR> expression, logical <A HREF="../v1ch4/predic.html">Ch4</A> <BR> extra inputs <A HREF="../v1ch2/proced.html">Ch2</A> <P><A NAME="F"></A> <BR> factorial <A HREF="../v1ch11/recops.html">Ch11</A> <BR> faith <A HREF="../v1ch8/recur2.html">Ch8</A> <BR> <CODE>false</CODE> <A HREF="../v1ch4/predic.html">Ch4</A> <BR> <CODE>fd</CODE> <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> Fibonacci sequence <A HREF="../v1ch5/hof.html">Ch5</A> , <A HREF="../v1ch11/recops.html">Ch11</A> <BR> <CODE>filter</CODE> <A HREF="../v1ch5/hof.html">Ch5</A> , <A HREF="../v1ch11/recops.html">Ch11</A> <BR> <CODE>find</CODE> <A HREF="../v1ch5/hof.html">Ch5</A> <BR> <CODE>first</CODE> <A HREF="../v1ch2/proced.html">Ch2</A> <BR> flag variable <A HREF="../v1ch6/ttt.html">Ch6</A> <BR> flat list <A HREF="../v1ch2/proced.html">Ch2</A> <BR> <CODE>for</CODE> <A HREF="../v1ch5/hof.html">Ch5</A> <BR> <CODE>foreach</CODE> <A HREF="../v1ch5/hof.html">Ch5</A> <BR> <CODE>forever</CODE> <A HREF="../v1ch6/ttt.html">Ch6</A> <BR> formal parameter <A HREF="../v1ch3/variab.html">Ch3</A> <BR> Fortran <A HREF="../v1ch0/preface.html">Pref</A> <BR> <CODE>forward</CODE> <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> <CODE>fput</CODE> <A HREF="../v1ch11/recops.html">Ch11</A> <BR> fractal <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> frame <A HREF="../v1ch3/variab.html">Ch3</A> <BR> Free Software Foundation <A HREF="appendix-gpl.html">GPL</A> <BR> Friedman, Batya <A HREF="../v1ch0/ack.html">Ack</A> <BR> front end, conversational <A HREF="../v1ch12/playfair.html">Ch12</A> <BR> function <A HREF="../v1ch5/hof.html">Ch5</A> <BR> function notation <A HREF="../v1ch2/proced.html">Ch2</A> <BR> function, higher order <A HREF="../v1ch5/hof.html">Ch5</A> <BR> functions, composition of <A HREF="../v1ch0/preface.html">Pref</A> , <A HREF="../v1ch2/proced.html">Ch2</A> , <A HREF="../v1ch12/playfair.html">Ch12</A> <P><A NAME="G"></A> <BR> geometry, analytic <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> geometry, turtle <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> Gilham, Fred <A HREF="../v1ch0/ack.html">Ack</A> <BR> global variable <A HREF="../v1ch3/variab.html">Ch3</A> <BR> Goldenberg, Paul <A HREF="../v1ch0/ack.html">Ack</A> <BR> Goodman, Paul <A HREF="../v1ch4/predic.html">Ch4</A> <BR> graph <A HREF="../v1ch14/pour.html">Ch14</A> <BR> graphics, computer <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> graphics, turtle <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> <CODE>greaterp</CODE> <A HREF="../v1ch4/predic.html">Ch4</A> <P><A NAME="H"></A> <BR> Hanoi, Tower of <A HREF="../v1ch8/recur2.html">Ch8</A> <BR> Harvey, Tessa <A HREF="../v1ch0/ack.html">Ack</A> <BR> <EM>Have His Carcase</EM> <A HREF="../v1ch12/playfair.html">Ch12</A> <BR> heading <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> <CODE>heading</CODE> <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> heading, compass <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> hierarchy of levels <A HREF="../v1ch9/recur3.html">Ch9</A> <BR> higher order function <A HREF="../v1ch5/hof.html">Ch5</A> <BR> Hoare, C. A. R. <A HREF="../v1ch13/plan.html">Ch13</A> <P><A NAME="I"></A> <BR> <CODE>if</CODE> <A HREF="../v1ch4/predic.html">Ch4</A> <BR> <CODE>ifelse</CODE> <A HREF="../v1ch4/predic.html">Ch4</A> , <A HREF="../v1ch13/plan.html">Ch13</A> <BR> <CODE>iff</CODE> <A HREF="../v1ch4/predic.html">Ch4</A> <BR> <CODE>iffalse</CODE> <A HREF="../v1ch4/predic.html">Ch4</A> <BR> <CODE>ift</CODE> <A HREF="../v1ch4/predic.html">Ch4</A> <BR> <CODE>iftrue</CODE> <A HREF="../v1ch4/predic.html">Ch4</A> <BR> increment <A HREF="../v1ch3/variab.html">Ch3</A> , <A HREF="../v1ch5/hof.html">Ch5</A> <BR> index variable <A HREF="../v1ch5/hof.html">Ch5</A> <BR> indirect assignment <A HREF="../v1ch3/variab.html">Ch3</A> <BR> infix arithmetic <A HREF="../v1ch2/proced.html">Ch2</A> <BR> initialization procedure <A HREF="../v1ch7/recur1.html">Ch7</A> , <A HREF="../v1ch8/recur2.html">Ch8</A> , <A HREF="../v1ch13/plan.html">Ch13</A> <BR> input <A HREF="../v1ch2/proced.html">Ch2</A> , <A HREF="../v1ch3/variab.html">Ch3</A> <BR> inputs, extra <A HREF="../v1ch2/proced.html">Ch2</A> <BR> instruction <A HREF="../v1ch1/explor.html">Ch1</A> , <A HREF="../v1ch2/proced.html">Ch2</A> <BR> instruction line <A HREF="../v1ch2/proced.html">Ch2</A> <BR> instruction list <A HREF="../v1ch4/predic.html">Ch4</A> <BR> intelligence, artificial <A HREF="../v1ch13/plan.html">Ch13</A> <BR> interaction <A HREF="../v1ch3/variab.html">Ch3</A> <BR> invocation <A HREF="../v1ch2/proced.html">Ch2</A> , <A HREF="../v1ch3/variab.html">Ch3</A> , <A HREF="../v1ch9/recur3.html">Ch9</A> <BR> IQ tests <A HREF="../v1ch14/pour.html">Ch14</A> <BR> <CODE>item</CODE> <A HREF="../v1ch2/proced.html">Ch2</A> , <A HREF="../v1ch6/ttt.html">Ch6</A> <BR> iteration, numeric <A HREF="../v1ch5/hof.html">Ch5</A> <P><A NAME="J"></A> <BR> joke <A HREF="../v1ch1/explor.html">Ch1</A> , <A HREF="../v1ch3/variab.html">Ch3</A> <P><A NAME="K"></A> <BR> Katz, Michael <A HREF="../v1ch0/ack.html">Ack</A> <BR> Katz, Yehuda <A HREF="../v1ch0/ack.html">Ack</A> <BR> kludge <A HREF="../v1ch2/proced.html">Ch2</A> <P><A NAME="L"></A> <BR> <CODE>last</CODE> <A HREF="../v1ch2/proced.html">Ch2</A> <BR> Latin, Pig <A HREF="../v1ch11/recops.html">Ch11</A> <BR> <CODE>left</CODE> <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> Lennon, John <A HREF="../v1ch1/explor.html">Ch1</A> , <A HREF="../v1ch4/predic.html">Ch4</A> <BR> <CODE>lessp</CODE> <A HREF="../v1ch4/predic.html">Ch4</A> <BR> levels of recursion <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> levels, hierarchy of <A HREF="../v1ch9/recur3.html">Ch9</A> <BR> Levington, David <A HREF="../v1ch0/ack.html">Ack</A> <BR> Lewis, Phil <A HREF="../v1ch0/ack.html">Ack</A> <BR> limit value <A HREF="../v1ch5/hof.html">Ch5</A> <BR> Lisp <A HREF="../v1ch0/preface.html">Pref</A> , <A HREF="../v1ch13/plan.html">Ch13</A> <BR> list <A HREF="../v1ch2/proced.html">Ch2</A> <BR> <CODE>list</CODE> <A HREF="../v1ch2/proced.html">Ch2</A> <BR> list, empty <A HREF="../v1ch2/proced.html">Ch2</A> <BR> list, flat <A HREF="../v1ch2/proced.html">Ch2</A> <BR> <CODE>listp</CODE> <A HREF="../v1ch4/predic.html">Ch4</A> <BR> <CODE>listtoarray</CODE> <A HREF="../v1ch6/ttt.html">Ch6</A> <BR> literacy, computer <A HREF="../v1ch0/preface.html">Pref</A> <BR> little person metaphor <A HREF="../v1ch3/variab.html">Ch3</A> , <A HREF="../v1ch9/recur3.html">Ch9</A> <BR> <CODE>local</CODE> <A HREF="../v1ch3/variab.html">Ch3</A> <BR> local variable <A HREF="../v1ch3/variab.html">Ch3</A> , <A HREF="../v1ch7/recur1.html">Ch7</A> , <A HREF="../v1ch9/recur3.html">Ch9</A> <BR> locality <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> logic, mathematical <A HREF="../v1ch0/preface.html">Pref</A> <BR> logical connective <A HREF="../v1ch4/predic.html">Ch4</A> <BR> logical expression <A HREF="../v1ch4/predic.html">Ch4</A> <BR> Logo <A HREF="../v1ch0/preface.html">Pref</A> , <A HREF="../v1ch13/plan.html">Ch13</A> <BR> <CODE>lput</CODE> <A HREF="../v1ch11/recops.html">Ch11</A> , <A HREF="../v1ch15/debug.html">Ch15</A> <BR> <CODE>lt</CODE> <A HREF="../v1ch10/turtle.html">Ch10</A> <P><A NAME="M"></A> <BR> <CODE>make</CODE> <A HREF="../v1ch3/variab.html">Ch3</A> <BR> <CODE>map</CODE> <A HREF="../v1ch5/hof.html">Ch5</A> <BR> <CODE>map.se</CODE> <A HREF="../v1ch5/hof.html">Ch5</A> <BR> mathematical logic <A HREF="../v1ch0/preface.html">Pref</A> <BR> mathematics <A HREF="../v1ch0/preface.html">Pref</A> <BR> matrix <A HREF="../v1ch0/preface.html">Pref</A> <BR> member <A HREF="../v1ch2/proced.html">Ch2</A> <BR> <CODE>memberp</CODE> <A HREF="../v1ch4/predic.html">Ch4</A> <BR> metaphor <A HREF="../v1ch1/explor.html">Ch1</A> , <A HREF="../v1ch3/variab.html">Ch3</A> , <A HREF="../v1ch9/recur3.html">Ch9</A> <BR> Mills, George <A HREF="../v1ch0/ack.html">Ack</A> <BR> Minsky, Margaret <A HREF="../v1ch0/ack.html">Ack</A> <BR> modularity <A HREF="../v1ch3/variab.html">Ch3</A> , <A HREF="../v1ch6/ttt.html">Ch6</A> , <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> most restrictive test <A HREF="../v1ch13/plan.html">Ch13</A> <P><A NAME="N"></A> <BR> name <A HREF="../v1ch3/variab.html">Ch3</A> <BR> <CODE>not</CODE> <A HREF="../v1ch4/predic.html">Ch4</A> <BR> number <A HREF="../v1ch2/proced.html">Ch2</A> , <A HREF="../v1ch4/predic.html">Ch4</A> <BR> number, telephone <A HREF="../v1ch14/pour.html">Ch14</A> <BR> <CODE>numberp</CODE> <A HREF="../v1ch4/predic.html">Ch4</A> <BR> numeral, Arabic <A HREF="../v1ch15/debug.html">Ch15</A> <BR> numeral, Roman <A HREF="../v1ch15/debug.html">Ch15</A> <BR> numeric iteration <A HREF="../v1ch5/hof.html">Ch5</A> <BR> numerical operation <A HREF="../v1ch11/recops.html">Ch11</A> <P><A NAME="O"></A> <BR> operation <A HREF="../v1ch2/proced.html">Ch2</A> , <A HREF="../v1ch3/variab.html">Ch3</A> , <A HREF="../v1ch4/predic.html">Ch4</A> <BR> operation, numerical <A HREF="../v1ch11/recops.html">Ch11</A> <BR> operation, recursive <A HREF="../v1ch11/recops.html">Ch11</A> <BR> operation, selection <A HREF="../v1ch11/recops.html">Ch11</A> <BR> <CODE>or</CODE> <A HREF="../v1ch4/predic.html">Ch4</A> <BR> origin <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> Orleans, Doug <A HREF="../v1ch0/ack.html">Ack</A> <BR> output <A HREF="../v1ch2/proced.html">Ch2</A> , <A HREF="../v1ch11/recops.html">Ch11</A> <BR> <CODE>output</CODE> <A HREF="../v1ch3/variab.html">Ch3</A> , <A HREF="../v1ch4/predic.html">Ch4</A> <BR> Owings, Sanford <A HREF="../v1ch0/ack.html">Ack</A> <P><A NAME="P"></A> <BR> parallel processing <A HREF="../v1ch14/pour.html">Ch14</A> <BR> parameter, formal <A HREF="../v1ch3/variab.html">Ch3</A> <BR> parentheses <A HREF="../v1ch2/proced.html">Ch2</A> , <A HREF="../v1ch4/predic.html">Ch4</A> <BR> Pascal <A HREF="../v1ch0/preface.html">Pref</A> , <A HREF="../v1ch2/proced.html">Ch2</A> , <A HREF="../v1ch13/plan.html">Ch13</A> <BR> pattern <A HREF="../v1ch8/recur2.html">Ch8</A> , <A HREF="../v1ch11/recops.html">Ch11</A> <BR> pattern, procedure <A HREF="../v1ch8/recur2.html">Ch8</A> <BR> <CODE>pause</CODE> <A HREF="../v1ch15/debug.html">Ch15</A> <BR> pausing <A HREF="../v1ch15/debug.html">Ch15</A> <BR> <CODE>pd</CODE> <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> pen <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> <CODE>pendown</CODE> <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> <CODE>penup</CODE> <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> Pig Latin <A HREF="../v1ch11/recops.html">Ch11</A> <BR> planning, style of <A HREF="../v1ch13/plan.html">Ch13</A> <BR> Playfair cipher <A HREF="../v1ch12/playfair.html">Ch12</A> <BR> plumbing diagram <A HREF="../v1ch2/proced.html">Ch2</A> <BR> <CODE>po</CODE> <A HREF="../v1ch2/proced.html">Ch2</A> <BR> pocket <A HREF="../v1ch3/variab.html">Ch3</A> <BR> <CODE>pons</CODE> <A HREF="../v1ch15/debug.html">Ch15</A> <BR> <CODE>pops</CODE> <A HREF="../v1ch2/proced.html">Ch2</A> <BR> <CODE>pos</CODE> <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> position <A HREF="../v1ch6/ttt.html">Ch6</A> , <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> <CODE>pots</CODE> <A HREF="../v1ch2/proced.html">Ch2</A> <BR> <CODE>pr</CODE> <A HREF="../v1ch2/proced.html">Ch2</A> <BR> predicate <A HREF="../v1ch4/predic.html">Ch4</A> <BR> predicate calculus <A HREF="../v1ch0/preface.html">Pref</A> <BR> predicate, recursive <A HREF="../v1ch11/recops.html">Ch11</A> <BR> prefix arithmetic <A HREF="../v1ch2/proced.html">Ch2</A> <BR> primitive <A HREF="../v1ch2/proced.html">Ch2</A> <BR> <CODE>print</CODE> <A HREF="../v1ch2/proced.html">Ch2</A> , <A HREF="../v1ch3/variab.html">Ch3</A> <BR> procedure <A HREF="../v1ch1/explor.html">Ch1</A> , <A HREF="../v1ch2/proced.html">Ch2</A> <BR> procedure pattern <A HREF="../v1ch8/recur2.html">Ch8</A> <BR> procedure, defining <A HREF="../v1ch2/proced.html">Ch2</A> <BR> procedure, initialization <A HREF="../v1ch7/recur1.html">Ch7</A> , <A HREF="../v1ch8/recur2.html">Ch8</A> , <A HREF="../v1ch13/plan.html">Ch13</A> <BR> procedure, top-level <A HREF="../v1ch3/variab.html">Ch3</A> <BR> processing, parallel <A HREF="../v1ch14/pour.html">Ch14</A> <BR> <CODE>product</CODE> <A HREF="../v1ch2/proced.html">Ch2</A> <BR> program <A HREF="../v1ch3/variab.html">Ch3</A> <BR> programming environment <A HREF="../v1ch1/explor.html">Ch1</A> <BR> programming, structured <A HREF="../v1ch13/plan.html">Ch13</A> <BR> Prolog <A HREF="../v1ch0/preface.html">Pref</A> <BR> prompt <A HREF="../v1ch1/explor.html">Ch1</A> <BR> psychology, cognitive <A HREF="../v1ch6/ttt.html">Ch6</A> <BR> <CODE>pu</CODE> <A HREF="../v1ch10/turtle.html">Ch10</A> <P><A NAME="Q"></A> <BR> question <A HREF="../v1ch4/predic.html">Ch4</A> <BR> question, yes-or-no <A HREF="../v1ch4/predic.html">Ch4</A> <BR> queue <A HREF="../v1ch14/pour.html">Ch14</A> <BR> quotation mark <A HREF="../v1ch2/proced.html">Ch2</A> , <A HREF="../v1ch3/variab.html">Ch3</A> <BR> quote <A HREF="../v1ch2/proced.html">Ch2</A> <P><A NAME="R"></A> <BR> <CODE>random</CODE> <A HREF="../v1ch5/hof.html">Ch5</A> <BR> range <A HREF="../v1ch5/hof.html">Ch5</A> <BR> <CODE>readchar</CODE> <A HREF="../v1ch6/ttt.html">Ch6</A> <BR> <CODE>readlist</CODE> <A HREF="../v1ch3/variab.html">Ch3</A> <BR> recursion <A HREF="../v1ch7/recur1.html">Ch7</A> <BR> recursion, levels of <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> recursive call <A HREF="../v1ch7/recur1.html">Ch7</A> , <A HREF="../v1ch11/recops.html">Ch11</A> <BR> recursive operation <A HREF="../v1ch11/recops.html">Ch11</A> <BR> <CODE>reduce</CODE> <A HREF="../v1ch5/hof.html">Ch5</A> , <A HREF="../v1ch11/recops.html">Ch11</A> <BR> redundancy, data <A HREF="../v1ch12/playfair.html">Ch12</A> <BR> <CODE>remainder</CODE> <A HREF="../v1ch2/proced.html">Ch2</A> <BR> <CODE>repeat</CODE> <A HREF="../v1ch4/predic.html">Ch4</A> <BR> representation, data <A HREF="../v1ch6/ttt.html">Ch6</A> , <A HREF="../v1ch14/pour.html">Ch14</A> <BR> restrictive test <A HREF="../v1ch13/plan.html">Ch13</A> <BR> <CODE>right</CODE> <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> right to left <A HREF="../v1ch2/proced.html">Ch2</A> <BR> Robbins, Herbert <A HREF="../v1ch14/pour.html">Ch14</A> <BR> robot <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> Roman numeral <A HREF="../v1ch15/debug.html">Ch15</A> <BR> <CODE>rt</CODE> <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> <CODE>run</CODE> <A HREF="../v1ch10/turtle.html">Ch10</A> <P><A NAME="S"></A> <BR> Sargent, Randy <A HREF="../v1ch0/ack.html">Ack</A> <BR> Sayers, Dorothy L. <A HREF="../v1ch12/playfair.html">Ch12</A> <BR> scope of variables <A HREF="../v1ch3/variab.html">Ch3</A> <BR> scope, dynamic <A HREF="../v1ch3/variab.html">Ch3</A> <BR> search, breadth-first <A HREF="../v1ch14/pour.html">Ch14</A> <BR> search, depth-first <A HREF="../v1ch14/pour.html">Ch14</A> <BR> search, tree <A HREF="../v1ch14/pour.html">Ch14</A> <BR> selection operation <A HREF="../v1ch11/recops.html">Ch11</A> <BR> selector <A HREF="../v1ch2/proced.html">Ch2</A> <BR> semantics <A HREF="../v1ch2/proced.html">Ch2</A> <BR> sentence <A HREF="../v1ch2/proced.html">Ch2</A> <BR> <CODE>sentence</CODE> <A HREF="../v1ch2/proced.html">Ch2</A> <BR> sequence of instructions <A HREF="../v1ch9/recur3.html">Ch9</A> <BR> <CODE>seth</CODE> <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> <CODE>setheading</CODE> <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> <CODE>setitem</CODE> <A HREF="../v1ch6/ttt.html">Ch6</A> <BR> <CODE>setpos</CODE> <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> simple substitution cipher <A HREF="../v1ch11/recops.html">Ch11</A> <BR> Solomon, Cynthia <A HREF="../v1ch0/ack.html">Ack</A> <BR> space/time tradeoff <A HREF="../v1ch12/playfair.html">Ch12</A> <BR> square bracket <A HREF="../v1ch2/proced.html">Ch2</A> , <A HREF="../v1ch4/predic.html">Ch4</A> <BR> stack <A HREF="../v1ch14/pour.html">Ch14</A> <BR> starting value <A HREF="../v1ch5/hof.html">Ch5</A> <BR> state, turtle <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> state-invariant <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> statement types <A HREF="../v1ch2/proced.html">Ch2</A> <BR> <CODE>step</CODE> <A HREF="../v1ch15/debug.html">Ch15</A> <BR> step, turtle <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> stepping <A HREF="../v1ch9/recur3.html">Ch9</A> , <A HREF="../v1ch15/debug.html">Ch15</A> <BR> <CODE>stop</CODE> <A HREF="../v1ch4/predic.html">Ch4</A> , <A HREF="../v1ch9/recur3.html">Ch9</A> <BR> stop rule <A HREF="../v1ch7/recur1.html">Ch7</A> , <A HREF="../v1ch8/recur2.html">Ch8</A> , <A HREF="../v1ch11/recops.html">Ch11</A> , <A HREF="../v1ch15/debug.html">Ch15</A> <BR> storage allocation <A HREF="../v1ch0/preface.html">Pref</A> <BR> string, character <A HREF="../v1ch2/proced.html">Ch2</A> <BR> structure, data <A HREF="../v1ch6/ttt.html">Ch6</A> <BR> structured programming <A HREF="../v1ch13/plan.html">Ch13</A> <BR> style of planning <A HREF="../v1ch13/plan.html">Ch13</A> <BR> subprocedure <A HREF="../v1ch3/variab.html">Ch3</A> , <A HREF="../v1ch7/recur1.html">Ch7</A> <BR> subprocedure/superprocedure diagram <A HREF="../v1ch6/ttt.html">Ch6</A> <BR> <CODE>subsets</CODE> <A HREF="../v1ch11/recops.html">Ch11</A> <BR> substitution cipher, simple <A HREF="../v1ch11/recops.html">Ch11</A> <BR> <CODE>sum</CODE> <A HREF="../v1ch2/proced.html">Ch2</A> <BR> superprocedure <A HREF="../v1ch3/variab.html">Ch3</A> <BR> symmetry <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> syntax <A HREF="../v1ch0/preface.html">Pref</A> , <A HREF="../v1ch2/proced.html">Ch2</A> <P><A NAME="T"></A> <BR> tail recursion <A HREF="../v1ch7/recur1.html">Ch7</A> , <A HREF="../v1ch11/recops.html">Ch11</A> <BR> telephone number <A HREF="../v1ch14/pour.html">Ch14</A> <BR> template <A HREF="../v1ch5/hof.html">Ch5</A> <BR> <CODE>test</CODE> <A HREF="../v1ch4/predic.html">Ch4</A> <BR> test, most restrictive <A HREF="../v1ch13/plan.html">Ch13</A> <BR> tests, IQ <A HREF="../v1ch14/pour.html">Ch14</A> <BR> <CODE>thing</CODE> <A HREF="../v1ch3/variab.html">Ch3</A> <BR> <CODE>throw</CODE> <A HREF="../v1ch15/debug.html">Ch15</A> <BR> tic-tac-toe <A HREF="../v1ch3/variab.html">Ch3</A> , <A HREF="../v1ch6/ttt.html">Ch6</A> , <A HREF="../v1ch13/plan.html">Ch13</A> <BR> title line <A HREF="../v1ch2/proced.html">Ch2</A> <BR> <CODE>to</CODE> <A HREF="../v1ch3/variab.html">Ch3</A> <BR> top-down <A HREF="../v1ch13/plan.html">Ch13</A> <BR> top-level procedure <A HREF="../v1ch3/variab.html">Ch3</A> <BR> Tower of Hanoi <A HREF="../v1ch8/recur2.html">Ch8</A> <BR> trace <A HREF="../v1ch9/recur3.html">Ch9</A> <BR> <CODE>trace</CODE> <A HREF="../v1ch15/debug.html">Ch15</A> <BR> tracing <A HREF="../v1ch9/recur3.html">Ch9</A> , <A HREF="../v1ch15/debug.html">Ch15</A> <BR> tree <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> tree search <A HREF="../v1ch14/pour.html">Ch14</A> <BR> <CODE>true</CODE> <A HREF="../v1ch4/predic.html">Ch4</A> <BR> turtle graphics <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> turtle step <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> turtle-relative <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> Twenty Questions <A HREF="../v1ch4/predic.html">Ch4</A> <BR> <CODE>type</CODE> <A HREF="../v1ch7/recur1.html">Ch7</A> <P><A NAME="V"></A> <BR> value, limit <A HREF="../v1ch5/hof.html">Ch5</A> <BR> value, starting <A HREF="../v1ch5/hof.html">Ch5</A> <BR> van Blerkom, Dan <A HREF="../v1ch0/ack.html">Ack</A> <BR> variable <A HREF="../v1ch3/variab.html">Ch3</A> <BR> variable, flag <A HREF="../v1ch6/ttt.html">Ch6</A> <BR> variable, index <A HREF="../v1ch5/hof.html">Ch5</A> <BR> variable, local <A HREF="../v1ch9/recur3.html">Ch9</A> <BR> variables in the workspace <A HREF="../v1ch6/ttt.html">Ch6</A> <P><A NAME="W"></A> <BR> Washington, George <A HREF="../v1ch4/predic.html">Ch4</A> <BR> <EM>What Is Mathematics?</EM> <A HREF="../v1ch14/pour.html">Ch14</A> <BR> Wirth, Niklaus <A HREF="../v1ch13/plan.html">Ch13</A> <BR> word <A HREF="../v1ch2/proced.html">Ch2</A> <BR> <CODE>word</CODE> <A HREF="../v1ch2/proced.html">Ch2</A> <BR> word, empty <A HREF="../v1ch2/proced.html">Ch2</A> <BR> <CODE>wordp</CODE> <A HREF="../v1ch4/predic.html">Ch4</A> <BR> Wright, Matthew <A HREF="../v1ch0/ack.html">Ack</A> , <A HREF="../v1ch6/ttt.html">Ch6</A> <P><A NAME="X"></A> <BR> x-coordinate <A HREF="../v1ch10/turtle.html">Ch10</A> <P><A NAME="Y"></A> <BR> y-coordinate <A HREF="../v1ch10/turtle.html">Ch10</A> <BR> yes-or-no question <A HREF="../v1ch4/predic.html">Ch4</A> <BR> Yoder, Sharon <A HREF="../v1ch0/ack.html">Ack</A> <P><A HREF="../v1-toc2.html">(back to Table of Contents)</A> <P><A HREF="appuindex.html"><STRONG>BACK</STRONG></A> chapter thread [no next] <P> <ADDRESS> <A HREF="../index.html">Brian Harvey</A>, <CODE>bh@cs.berkeley.edu</CODE> </ADDRESS> </BODY> </HTML>