FAUST compiler  0.9.9.6b8
Functions | Variables
list.cpp File Reference
#include <stdlib.h>
#include "list.hh"
#include "compatibility.hh"
#include <map>
#include <cstdlib>
Include dependency graph for list.cpp:

Go to the source code of this file.

Functions

static bool printlist (Tree l, FILE *out)
 
void print (Tree t, FILE *out)
 
Tree nth (Tree l, int i)
 
Tree replace (Tree l, int i, Tree e)
 
int len (Tree l)
 
Tree rconcat (Tree l, Tree q)
 
Tree concat (Tree l, Tree q)
 
Tree lrange (Tree l, int i, int j)
 
static Tree rmap (tfun f, Tree l)
 
Tree reverse (Tree l)
 
Tree lmap (tfun f, Tree l)
 
Tree reverseall (Tree l)
 
bool isElement (Tree e, Tree l)
 
Tree addElement (Tree e, Tree l)
 
Tree remElement (Tree e, Tree l)
 
Tree singleton (Tree e)
 
Tree list2set (Tree l)
 
Tree setUnion (Tree A, Tree B)
 
Tree setIntersection (Tree A, Tree B)
 
Tree setDifference (Tree A, Tree B)
 
Tree pushEnv (Tree key, Tree val, Tree env)
 
bool searchEnv (Tree key, Tree &v, Tree env)
 
static bool findKey (Tree pl, Tree key, Tree &val)
 
static Tree updateKey (Tree pl, Tree key, Tree val)
 
static Tree removeKey (Tree pl, Tree key)
 
void setProperty (Tree t, Tree key, Tree val)
 
bool getProperty (Tree t, Tree key, Tree &val)
 
void remProperty (Tree t, Tree key)
 
Tree tmap (Tree key, tfun f, Tree t)
 
static Tree substkey (Tree t, Tree id, Tree val)
 
static Tree subst (Tree t, Tree propkey, Tree id, Tree val)
 
Tree substitute (Tree t, Tree id, Tree val)
 

Variables

Sym CONS = symbol("cons")
 
Sym NIL = symbol("nil")
 
Tree nil = tree(NIL)
 

Function Documentation

Tree addElement ( Tree  e,
Tree  l 
)

Definition at line 272 of file list.cpp.

References addElement(), cons(), hd(), isList(), and tl().

Referenced by addElement(), evalIdDef(), list2set(), and ppsig::printrec().

273 {
274  if (isList(l)) {
275  if (e < hd(l)) {
276  return cons(e,l);
277  } else if (e == hd(l)) {
278  return l;
279  } else {
280  return cons(hd(l), addElement(e,tl(l)));
281  }
282  } else {
283  return cons(e,nil);
284  }
285 }
Tree addElement(Tree e, Tree l)
Definition: list.cpp:272
Tree cons(Tree a, Tree b)
Definition: list.hh:124
Tree hd(Tree l)
Definition: list.hh:133
bool isList(Tree l)
Definition: list.hh:138
Tree nil
Definition: list.cpp:116
Tree tl(Tree l)
Definition: list.hh:134

Here is the call graph for this function:

Here is the caller graph for this function:

Tree concat ( Tree  l,
Tree  q 
)

Definition at line 216 of file list.cpp.

References rconcat(), and reverse().

Referenced by applyList(), and sigCartesianProd().

217 {
218  return rconcat(reverse(l), q);
219 }
Tree reverse(Tree l)
Definition: list.cpp:240
Tree rconcat(Tree l, Tree q)
Definition: list.cpp:210

Here is the call graph for this function:

Here is the caller graph for this function:

static bool findKey ( Tree  pl,
Tree  key,
Tree val 
)
static

Definition at line 373 of file list.cpp.

References hd(), isNil(), left(), right(), and tl().

374 {
375  if (isNil(pl)) return false;
376  if (left(hd(pl)) == key) { val= right(hd(pl)); return true; }
377  /* left(hd(pl)) != key */ return findKey (tl(pl), key, val);
378 }
Tree left(Tree t)
Definition: list.hh:170
Tree hd(Tree l)
Definition: list.hh:133
Tree right(Tree t)
Definition: list.hh:171
bool isNil(Tree l)
Definition: list.hh:137
static bool findKey(Tree pl, Tree key, Tree &val)
Definition: list.cpp:373
Tree tl(Tree l)
Definition: list.hh:134

Here is the call graph for this function:

bool getProperty ( Tree  t,
Tree  key,
Tree val 
)

Definition at line 423 of file list.cpp.

References CTree::getProperty().

Referenced by addLayerDef(), annotate(), evalIdDef(), getBoxType(), getColorProperty(), Occurrences::getCount(), getDefFileProp(), getDefLineProp(), getDefNameProperty(), getEvalProperty(), getNumericProperty(), getPMProperty(), getPropagateProperty(), getRecursivness(), ScalarCompiler::getSharingCount(), DocCompiler::getSharingCount(), getSigNickname(), getSigOrder(), privatisation(), searchIdDef(), shcount(), sigMap(), sigMapRename(), subst(), and tmap().

424 {
425  CTree* pl = t->getProperty(key);
426  if (pl) {
427  val = pl;
428  return true;
429  } else {
430  return false;
431  }
432 }
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
Tree getProperty(Tree key)
Definition: tree.hh:173

Here is the call graph for this function:

Here is the caller graph for this function:

bool isElement ( Tree  e,
Tree  l 
)

Definition at line 262 of file list.cpp.

References hd(), isList(), and tl().

263 {
264  while (isList(l)) {
265  if (hd(l) == e) return true;
266  if (hd(l) > e) return false;
267  l = tl(l);
268  }
269  return false;
270 }
Tree hd(Tree l)
Definition: list.hh:133
bool isList(Tree l)
Definition: list.hh:138
Tree tl(Tree l)
Definition: list.hh:134

Here is the call graph for this function:

int len ( Tree  l)

Definition at line 198 of file list.cpp.

References isList(), and tl().

Referenced by checkRulelist(), evalCase(), ffarity(), ScalarCompiler::generateRec(), DocCompiler::generateRec(), make_pattern_matcher(), makeDefinition(), Symbol::Symbol(), symlistVisit(), and typeAnnotation().

199 {
200  int n = 0;
201  while (isList(l)) { l = tl(l); n++; }
202  return n;
203 }
bool isList(Tree l)
Definition: list.hh:138
Tree tl(Tree l)
Definition: list.hh:134

Here is the call graph for this function:

Here is the caller graph for this function:

Tree list2set ( Tree  l)

Definition at line 307 of file list.cpp.

References addElement(), hd(), isList(), nil, and tl().

308 {
309  Tree s = nil;
310  while (isList(l)) {
311  s = addElement(hd(l),s);
312  l = tl(l);
313  }
314  return s;
315 }
Tree addElement(Tree e, Tree l)
Definition: list.cpp:272
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
Tree hd(Tree l)
Definition: list.hh:133
bool isList(Tree l)
Definition: list.hh:138
Tree nil
Definition: list.cpp:116
Tree tl(Tree l)
Definition: list.hh:134

Here is the call graph for this function:

Tree lmap ( tfun  f,
Tree  l 
)

Definition at line 247 of file list.cpp.

References reverse(), and rmap().

Referenced by preparePattern(), prepareRule(), and prepareRules().

248 {
249  return reverse(rmap(f,l));
250 }
Tree reverse(Tree l)
Definition: list.cpp:240
static Tree rmap(tfun f, Tree l)
Definition: list.cpp:233

Here is the call graph for this function:

Here is the caller graph for this function:

Tree lrange ( Tree  l,
int  i,
int  j 
)

Definition at line 221 of file list.cpp.

References cons(), nil, and nth().

222 {
223  Tree r = nil;
224  int c = j;
225  while (c>i) r = cons( nth(l,--c), r);
226  return r;
227 }
Tree cons(Tree a, Tree b)
Definition: list.hh:124
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
Tree nil
Definition: list.cpp:116
Tree nth(Tree l, int i)
Definition: list.cpp:182

Here is the call graph for this function:

Tree nth ( Tree  l,
int  i 
)

Definition at line 182 of file list.cpp.

References hd(), isList(), nil, and tl().

Referenced by ffargtype(), ffname(), ScalarCompiler::generateFFun(), DocCompiler::generateFFun(), ScalarCompiler::generateRec(), DocCompiler::generateRec(), isBoxHSlider(), isBoxNumEntry(), isBoxVSlider(), isSigHSlider(), isSigNumEntry(), isSigVSlider(), lrange(), boxpp::print(), and symlistVisit().

183 {
184  while (isList(l)) {
185  if (i == 0) return hd(l);
186  l = tl(l);
187  i--;
188  }
189  return nil;
190 }
Tree hd(Tree l)
Definition: list.hh:133
bool isList(Tree l)
Definition: list.hh:138
Tree nil
Definition: list.cpp:116
Tree tl(Tree l)
Definition: list.hh:134

Here is the call graph for this function:

Here is the caller graph for this function:

void print ( Tree  t,
FILE *  out 
)

Definition at line 154 of file list.cpp.

References CTree::arity(), CTree::branch(), isDouble(), isInt(), isPointer(), isSym(), name(), CTree::node(), print(), and printlist().

Referenced by addLayerDef(), evalerror(), evalremark(), evalwarning(), ScalarCompiler::generateCode(), generateInsideSchema(), infereSigOrder(), infereSigType(), print(), printlist(), and printSignal().

155 {
156  int i; double f; Sym s; void* p;
157 
158  if (printlist(t, out)) return;
159 
160  Node n = t->node();
161  if (isInt(n, &i)) fprintf (out, "%d", i);
162  else if (isDouble(n, &f)) fprintf (out, "%f", f);
163  else if (isSym(n, &s)) fprintf (out, "%s", name(s));
164  else if (isPointer(n, &p)) fprintf (out, "#%p", p);
165 
166  int k = t->arity();
167  if (k > 0) {
168  char sep = '[';
169  for (int i=0; i<k; i++) {
170  fputc(sep, out); sep = ',';
171  print(t->branch(i), out);
172  }
173  fputc(']', out);
174  }
175 }
static bool printlist(Tree l, FILE *out)
Definition: list.cpp:123
Class Node = (type x (int + double + Sym + void*))
Definition: node.hh:75
const Node & node() const
return the content of the tree
Definition: tree.hh:143
bool isDouble(const Node &n)
Definition: node.hh:143
bool isSym(const Node &n)
Definition: node.hh:199
int arity() const
return the number of branches (subtrees) of a tree
Definition: tree.hh:144
const char * name(Symbol *sym)
Returns the name of a symbol.
Definition: symbol.hh:98
Symbols are unique objects with a name stored in a hash table.
Definition: symbol.hh:53
bool isPointer(const Node &n)
Definition: node.hh:216
bool isInt(const Node &n)
Definition: node.hh:126
Tree branch(int i) const
return the ith branch (subtree) of a tree
Definition: tree.hh:145
void print(Tree t, FILE *out)
Definition: list.cpp:154

Here is the call graph for this function:

Here is the caller graph for this function:

static bool printlist ( Tree  l,
FILE *  out 
)
static

Definition at line 123 of file list.cpp.

References hd(), isList(), isNil(), print(), and tl().

Referenced by print().

124 {
125  if (isList(l)) {
126 
127  char sep = '(';
128 
129  do {
130  fputc(sep, out); sep = ',';
131  print(hd(l));
132  l = tl(l);
133  } while (isList(l));
134 
135  if (! isNil(l)) {
136  fprintf(out, " . ");
137  print(l, out);
138  }
139 
140  fputc(')', out);
141  return true;
142 
143  } else if (isNil(l)) {
144 
145  fprintf(out, "nil");
146  return true;
147 
148  } else {
149 
150  return false;
151  }
152 }
Tree hd(Tree l)
Definition: list.hh:133
bool isNil(Tree l)
Definition: list.hh:137
bool isList(Tree l)
Definition: list.hh:138
Tree tl(Tree l)
Definition: list.hh:134
void print(Tree t, FILE *out)
Definition: list.cpp:154

Here is the call graph for this function:

Here is the caller graph for this function:

Tree pushEnv ( Tree  key,
Tree  val,
Tree  env 
)

Definition at line 351 of file list.cpp.

References cons().

Referenced by realPropagate(), and sigMapRename().

352 {
353  return cons (cons(key,val), env);
354 }
Tree cons(Tree a, Tree b)
Definition: list.hh:124

Here is the call graph for this function:

Here is the caller graph for this function:

Tree rconcat ( Tree  l,
Tree  q 
)

Definition at line 210 of file list.cpp.

References cons(), hd(), isList(), and tl().

Referenced by concat().

211 {
212  while (isList(l)) { q = cons(hd(l),q); l = tl(l); }
213  return q;
214 }
Tree cons(Tree a, Tree b)
Definition: list.hh:124
Tree hd(Tree l)
Definition: list.hh:133
bool isList(Tree l)
Definition: list.hh:138
Tree tl(Tree l)
Definition: list.hh:134

Here is the call graph for this function:

Here is the caller graph for this function:

Tree remElement ( Tree  e,
Tree  l 
)

Definition at line 287 of file list.cpp.

References cons(), hd(), isList(), nil, remElement(), and tl().

Referenced by remElement().

288 {
289  if (isList(l)) {
290  if (e < hd(l)) {
291  return l;
292  } else if (e == hd(l)) {
293  return tl(l);
294  } else {
295  return cons(hd(l), remElement(e,tl(l)));
296  }
297  } else {
298  return nil;
299  }
300 }
Tree cons(Tree a, Tree b)
Definition: list.hh:124
Tree remElement(Tree e, Tree l)
Definition: list.cpp:287
Tree hd(Tree l)
Definition: list.hh:133
bool isList(Tree l)
Definition: list.hh:138
Tree nil
Definition: list.cpp:116
Tree tl(Tree l)
Definition: list.hh:134

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree removeKey ( Tree  pl,
Tree  key 
)
static

Definition at line 387 of file list.cpp.

References cons(), hd(), isNil(), left(), nil, and tl().

388 {
389  if (isNil(pl)) return nil;
390  if (left(hd(pl)) == key) return tl(pl);
391  /* left(hd(pl)) != key */ return cons (hd(pl), removeKey(tl(pl), key));
392 }
Tree cons(Tree a, Tree b)
Definition: list.hh:124
Tree left(Tree t)
Definition: list.hh:170
Tree hd(Tree l)
Definition: list.hh:133
bool isNil(Tree l)
Definition: list.hh:137
static Tree removeKey(Tree pl, Tree key)
Definition: list.cpp:387
Tree nil
Definition: list.cpp:116
Tree tl(Tree l)
Definition: list.hh:134

Here is the call graph for this function:

void remProperty ( Tree  t,
Tree  key 
)

Definition at line 434 of file list.cpp.

435 {
436  exit(1); // fonction not implemented
437 }
Tree replace ( Tree  l,
int  i,
Tree  e 
)

Definition at line 192 of file list.cpp.

References cons(), hd(), replace(), and tl().

Referenced by replace().

193 {
194  return (i==0) ? cons(e,tl(l)) : cons( hd(l), replace(tl(l),i-1,e) );
195 }
Tree cons(Tree a, Tree b)
Definition: list.hh:124
Tree hd(Tree l)
Definition: list.hh:133
Tree replace(Tree l, int i, Tree e)
Definition: list.cpp:192
Tree tl(Tree l)
Definition: list.hh:134

Here is the call graph for this function:

Here is the caller graph for this function:

Tree reverse ( Tree  l)

Definition at line 240 of file list.cpp.

References cons(), hd(), isList(), nil, and tl().

Referenced by applyList(), collectDocEqns(), concat(), ScalarCompiler::generateButton(), ScalarCompiler::generateCheckbox(), ScalarCompiler::generateHBargraph(), ScalarCompiler::generateHSlider(), ScalarCompiler::generateNumEntry(), ScalarCompiler::generateVBargraph(), ScalarCompiler::generateVSlider(), DocCompiler::getUIDir(), lmap(), make_pattern_matcher(), printdoccontent(), and printPatternError().

241 {
242  Tree r = nil;
243  while (isList(l)) { r = cons(hd(l),r); l = tl(l); }
244  return r;
245 }
Tree cons(Tree a, Tree b)
Definition: list.hh:124
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
Tree hd(Tree l)
Definition: list.hh:133
bool isList(Tree l)
Definition: list.hh:138
Tree nil
Definition: list.cpp:116
Tree tl(Tree l)
Definition: list.hh:134

Here is the call graph for this function:

Here is the caller graph for this function:

Tree reverseall ( Tree  l)

Definition at line 252 of file list.cpp.

References isList(), reverseall(), and rmap().

Referenced by reverseall().

253 {
254  return isList(l) ? rmap(reverseall, l) : l;
255 }
Tree reverseall(Tree l)
Definition: list.cpp:252
static Tree rmap(tfun f, Tree l)
Definition: list.cpp:233
bool isList(Tree l)
Definition: list.hh:138

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree rmap ( tfun  f,
Tree  l 
)
static

Definition at line 233 of file list.cpp.

References cons(), hd(), isList(), nil, and tl().

Referenced by lmap(), and reverseall().

234 {
235  Tree r = nil;
236  while (isList(l)) { r = cons(f(hd(l)),r); l = tl(l); }
237  return r;
238 }
Tree cons(Tree a, Tree b)
Definition: list.hh:124
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
Tree hd(Tree l)
Definition: list.hh:133
bool isList(Tree l)
Definition: list.hh:138
Tree nil
Definition: list.cpp:116
Tree tl(Tree l)
Definition: list.hh:134

Here is the call graph for this function:

Here is the caller graph for this function:

bool searchEnv ( Tree  key,
Tree v,
Tree  env 
)

Definition at line 356 of file list.cpp.

References hd(), isList(), and tl().

Referenced by realPropagate(), and sigMapRename().

357 {
358  while (isList(env)) {
359  if (hd(hd(env)) == key) {
360  v = tl(hd(env));
361  return true;
362  }
363  env = tl(env);
364  }
365  return false;
366 }
Tree hd(Tree l)
Definition: list.hh:133
bool isList(Tree l)
Definition: list.hh:138
Tree tl(Tree l)
Definition: list.hh:134

Here is the call graph for this function:

Here is the caller graph for this function:

Tree setDifference ( Tree  A,
Tree  B 
)

Definition at line 336 of file list.cpp.

References cons(), hd(), isNil(), setDifference(), and tl().

Referenced by setDifference().

337 {
338  if (isNil(A)) return A;
339  if (isNil(B)) return A;
340  if (hd(A) == hd(B)) return setDifference(tl(A),tl(B));
341  if (hd(A) < hd(B)) return cons(hd(A), setDifference(tl(A),B));
342  /* (hd(A) > hd(B)*/ return setDifference(A,tl(B));
343 }
Tree cons(Tree a, Tree b)
Definition: list.hh:124
Tree hd(Tree l)
Definition: list.hh:133
bool isNil(Tree l)
Definition: list.hh:137
Tree setDifference(Tree A, Tree B)
Definition: list.cpp:336
Tree tl(Tree l)
Definition: list.hh:134

Here is the call graph for this function:

Here is the caller graph for this function:

Tree setIntersection ( Tree  A,
Tree  B 
)

Definition at line 327 of file list.cpp.

References cons(), hd(), isNil(), setIntersection(), and tl().

Referenced by Loop::hasRecDependencyIn(), and setIntersection().

328 {
329  if (isNil(A)) return A;
330  if (isNil(B)) return B;
331  if (hd(A) == hd(B)) return cons(hd(A), setIntersection(tl(A),tl(B)));
332  if (hd(A) < hd(B)) return setIntersection(tl(A),B);
333  /* (hd(A) > hd(B)*/ return setIntersection(A,tl(B));
334 }
Tree cons(Tree a, Tree b)
Definition: list.hh:124
Tree hd(Tree l)
Definition: list.hh:133
Tree setIntersection(Tree A, Tree B)
Definition: list.cpp:327
bool isNil(Tree l)
Definition: list.hh:137
Tree tl(Tree l)
Definition: list.hh:134

Here is the call graph for this function:

Here is the caller graph for this function:

void setProperty ( Tree  t,
Tree  key,
Tree  val 
)
Tree setUnion ( Tree  A,
Tree  B 
)

Definition at line 317 of file list.cpp.

References cons(), hd(), isNil(), setUnion(), and tl().

Referenced by Loop::absorb(), realeval(), setUnion(), and symlistVisit().

318 {
319  if (isNil(A)) return B;
320  if (isNil(B)) return A;
321 
322  if (hd(A) == hd(B)) return cons(hd(A), setUnion(tl(A),tl(B)));
323  if (hd(A) < hd(B)) return cons(hd(A), setUnion(tl(A),B));
324  /* hd(A) > hd(B) */ return cons(hd(B), setUnion(A,tl(B)));
325 }
Tree cons(Tree a, Tree b)
Definition: list.hh:124
Tree hd(Tree l)
Definition: list.hh:133
bool isNil(Tree l)
Definition: list.hh:137
Tree setUnion(Tree A, Tree B)
Definition: list.cpp:317
Tree tl(Tree l)
Definition: list.hh:134

Here is the call graph for this function:

Here is the caller graph for this function:

Tree singleton ( Tree  e)

Definition at line 302 of file list.cpp.

References list1().

Referenced by VectorCompiler::generateLoopCode(), and symlistVisit().

303 {
304  return list1(e);
305 }
Tree list1(Tree a)
Definition: list.hh:127

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree subst ( Tree  t,
Tree  propkey,
Tree  id,
Tree  val 
)
static

Definition at line 493 of file list.cpp.

References CTree::arity(), CTree::branch(), getProperty(), isNil(), CTree::node(), setProperty(), and tree().

Referenced by substitute().

494 {
495  Tree p;
496 
497  if (t==id) {
498  return val;
499 
500  } else if (t->arity() == 0) {
501  return t;
502  } else if (getProperty(t, propkey, p)) {
503  return (isNil(p)) ? t : p;
504  } else {
505 
506  tvec br;
507  int n = t->arity();
508  for (int i = 0; i < n; i++) {
509  br.push_back( subst(t->branch(i), propkey, id, val) );
510  }
511 
512  Tree r = tree(t->node(), br);
513 
514  if (r == t) {
515  setProperty(t, propkey, nil);
516  } else {
517  setProperty(t, propkey, r);
518  }
519  return r;
520  }
521 
522 }
static Tree subst(Tree t, Tree propkey, Tree id, Tree val)
Definition: list.cpp:493
vector< Tree > tvec
Definition: tree.hh:90
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
const Node & node() const
return the content of the tree
Definition: tree.hh:143
bool isNil(Tree l)
Definition: list.hh:137
int arity() const
return the number of branches (subtrees) of a tree
Definition: tree.hh:144
Tree tree(const Node &n)
Definition: tree.hh:186
void setProperty(Tree t, Tree key, Tree val)
Definition: list.cpp:418
Tree nil
Definition: list.cpp:116
Tree branch(int i) const
return the ith branch (subtree) of a tree
Definition: tree.hh:145
bool getProperty(Tree t, Tree key, Tree &val)
Definition: list.cpp:423

Here is the call graph for this function:

Here is the caller graph for this function:

Tree substitute ( Tree  t,
Tree  id,
Tree  val 
)

Definition at line 525 of file list.cpp.

References subst(), and substkey().

526 {
527  return subst (t, substkey(t,id,val), id, val);
528 }
static Tree substkey(Tree t, Tree id, Tree val)
Definition: list.cpp:483
static Tree subst(Tree t, Tree propkey, Tree id, Tree val)
Definition: list.cpp:493

Here is the call graph for this function:

static Tree substkey ( Tree  t,
Tree  id,
Tree  val 
)
static

Definition at line 483 of file list.cpp.

References name(), tree(), and unique().

Referenced by substitute().

484 {
485  char name[256];
486  snprintf(name, 255, "SUBST<%p,%p,%p> : ", (CTree*)t, (CTree*)id, (CTree*)val);
487  return tree(unique(name));
488 }
Symbol * unique(const char *str)
Returns a new unique symbol of name strxxx.
Definition: symbol.hh:97
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
const char * name(Symbol *sym)
Returns the name of a symbol.
Definition: symbol.hh:98
Tree tree(const Node &n)
Definition: tree.hh:186

Here is the call graph for this function:

Here is the caller graph for this function:

Tree tmap ( Tree  key,
tfun  f,
Tree  t 
)

Definition at line 445 of file list.cpp.

References CTree::arity(), CTree::branch(), getProperty(), isNil(), CTree::node(), setProperty(), tmap(), and tree().

Referenced by tmap().

446 {
447  //printf("start tmap\n");
448  Tree p;
449 
450  if (getProperty(t, key, p)) {
451 
452  return (isNil(p)) ? t : p; // truc pour eviter les boucles
453 
454  } else {
455 
456  tvec br;
457  int n = t->arity();
458  for (int i = 0; i < n; i++) {
459  br.push_back( tmap(key, f, t->branch(i)) );
460  }
461 
462  Tree r1 = tree(t->node(), br);
463 
464  Tree r2 = f(r1);
465  if (r2 == t) {
466  setProperty(t, key, nil);
467  } else {
468  setProperty(t, key, r2);
469  }
470  return r2;
471  }
472 }
vector< Tree > tvec
Definition: tree.hh:90
A CTree = (Node x [CTree]) is a Node associated with a list of subtrees called branches.
Definition: tree.hh:109
const Node & node() const
return the content of the tree
Definition: tree.hh:143
bool isNil(Tree l)
Definition: list.hh:137
Tree tmap(Tree key, tfun f, Tree t)
Definition: list.cpp:445
int arity() const
return the number of branches (subtrees) of a tree
Definition: tree.hh:144
Tree tree(const Node &n)
Definition: tree.hh:186
void setProperty(Tree t, Tree key, Tree val)
Definition: list.cpp:418
Tree nil
Definition: list.cpp:116
Tree branch(int i) const
return the ith branch (subtree) of a tree
Definition: tree.hh:145
bool getProperty(Tree t, Tree key, Tree &val)
Definition: list.cpp:423

Here is the call graph for this function:

Here is the caller graph for this function:

static Tree updateKey ( Tree  pl,
Tree  key,
Tree  val 
)
static

Definition at line 380 of file list.cpp.

References cons(), hd(), isNil(), left(), and tl().

381 {
382  if (isNil(pl)) return cons ( cons(key,val), nil );
383  if (left(hd(pl)) == key) return cons ( cons(key,val), tl(pl) );
384  /* left(hd(pl)) != key */ return cons ( hd(pl), updateKey( tl(pl), key, val ));
385 }
Tree cons(Tree a, Tree b)
Definition: list.hh:124
Tree left(Tree t)
Definition: list.hh:170
Tree hd(Tree l)
Definition: list.hh:133
bool isNil(Tree l)
Definition: list.hh:137
static Tree updateKey(Tree pl, Tree key, Tree val)
Definition: list.cpp:380
Tree nil
Definition: list.cpp:116
Tree tl(Tree l)
Definition: list.hh:134

Here is the call graph for this function:

Variable Documentation

Sym CONS = symbol("cons")

Definition at line 112 of file list.cpp.

Sym NIL = symbol("nil")

Definition at line 113 of file list.cpp.

Tree nil = tree(NIL)