home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / gwm18a.zip / data / dlists.gwm < prev    next >
Lisp/Scheme  |  1995-07-03  |  1KB  |  65 lines

  1. ; Dynamic lists
  2. ; ==============
  3.  
  4. ;;File: dlists.gwm -- manage dynamic lists
  5. ;;Author: colas@mirsa.inria.fr (Colas NAHABOO) -- Bull Research FRANCE
  6. ;;Revision: 2 -- Dec 20 1989
  7. ;;State: Exp
  8. ;;GWM Version: 1.4
  9.  
  10. (setq Dlists t)                ;package is loaded
  11.  
  12. ; making a new list:
  13. ; (Dlists.make)
  14. ; of name foo: (Dlists.make 'foo)
  15. ; with pre-set size n: (Dlists.make n)
  16.  
  17. (defunq Dlists.make args
  18.   (with (list.name ())
  19.     (if (not args) 
  20.     (set (setq list.name (Dlists.name.new)) ())
  21.       (= (type (# 0 args)) 'number)
  22.       (set (setq list.name (Dlists.name.new)) (list-make (# 0 args)))
  23.       t
  24.       (set (setq list.name (# 0 args)) ()))
  25.     list.name))    
  26.  
  27. (setq Dlists.name.count 0)        ;gensyms for Dlists: Dlist#78
  28. (defun Dlists.name.new ()
  29.   (atom (+ "Dlist#" (itoa (setq Dlists.name.count
  30.                 (+ Dlists.name.count 1))))))
  31. ; appending one element
  32.  
  33. (defun Dlists.append (l obj)
  34.    (## (length (eval l)) l obj))
  35.  
  36. ; removing an element (returns pos)
  37.  
  38. (defun Dlists.remove (l obj)
  39.     (if (setq Dlists.remove.pos (member obj (eval l)))
  40.     (progn
  41.       (delete-nth Dlists.remove.pos (eval l))
  42.       Dlists.remove.pos
  43.       )
  44.       0
  45.       )
  46.     )
  47.  
  48. ; getting the list of a Dlist
  49.  
  50. (defun Dlists.list (dlist)
  51.   (eval dlist))
  52.  
  53. ; getting the length of a Dlist
  54.  
  55. (defun Dlists.length (dlist)
  56.   (length (Dlists.list dlist)))
  57.  
  58. ; setting the list of a dlist to some list (which is copied into it)
  59.  
  60. (defun Dlists.set (dlist l)
  61.   (set dlist l))
  62.  
  63.  
  64.  
  65.