home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / a / armbob / !ArmBob / progs / h / list < prev    next >
Text File  |  1994-06-06  |  560b  |  44 lines

  1. /* GCW  06/06/94  */
  2. /* lists */
  3.  
  4. cons(x,list)
  5. {
  6.  local node;
  7.  node = newvector(2);
  8.  node[0] = x;
  9.  node[1] = list;
  10.  return node;
  11. }
  12.  
  13. head(list)
  14. {
  15.  return ((typeof(list)==VECTOR)?(list[0]):nil);
  16. }
  17.  
  18. tail(list)
  19. {
  20.  return ((typeof(list)==VECTOR)?(list[1]):nil);
  21. }
  22.  
  23. map(f,l)
  24. {
  25.  return ((typeof(l)==VECTOR)?(cons(f(head(l)),map(f,tail(l)))):nil);
  26. }
  27.  
  28. printlist(l)
  29. {
  30.  print("[");
  31.  if (typeof(l)==VECTOR)
  32.    {
  33.     print(head(l));
  34.     l = tail(l);
  35.     while (typeof(l)==VECTOR)
  36.      {
  37.       print(",");
  38.       print(head(l));
  39.       l = tail(l);
  40.      }
  41.    }
  42.  print("]");
  43. }
  44.