home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / windows / winlisp.zip / OOPL.LZH / COLLECT.WL next >
Text File  |  1989-03-19  |  3KB  |  77 lines

  1. ;===============================================================================
  2. ;
  3. ;               C O L L E C T I O N S
  4. ;
  5. ;===============================================================================
  6. [{AbstractClass} new 'name 'MetaCollection
  7.     'superClass        {Class}
  8.         'methods        '(
  9. new ( elements                                   
  10.       ;; --------------------------------------------------------------
  11.       ;; Answer a new collection that contains all the objects of 
  12.       ;; <elements> if this list is provided else answer an empty
  13.       ;; collection.
  14.       ;; --------------------------------------------------------------
  15.       )
  16. )]
  17.  
  18. [{AbstractClass} new 'name 'Collection
  19.     'superClass         {Object}
  20.         'methods        '(
  21. isEmpty (()    
  22.          ;; ----------------------------------------------------------
  23.          ;; Answer something true if the receiver is empty else answer
  24.          ;; nil.
  25.          ;; ----------------------------------------------------------
  26.         (equal [self size] 0))
  27.  
  28. do ((aLambda)
  29.     ;; --------------------------------------------------------------
  30.     ;; For each element in the receiver, evaluate aLambda with that
  31.     ;; element as its argument.
  32.     ;; Answer the receiver.
  33.     ;; --------------------------------------------------------------
  34.     )
  35.  
  36. size (()
  37.       ;; --------------------------------------------------------------
  38.       ;; Answer the number of elements of the receiver.
  39.       ;; --------------------------------------------------------------
  40.     )
  41. )]
  42.  
  43. [{Class} new 'name 'MetaDictionary
  44.     'superClass        {MetaCollection}
  45.         'methods        '(
  46. new ( elements
  47.        ;; --------------------------------------------------------------
  48.        ;; Notice here that elements must be a list like:
  49.        ;;    ((key1 . value1) ... (keyN . valueN))
  50.        ;; --------------------------------------------------------------
  51.            (let ( (newDictionary [super new 'aSymbol [{symbol} new]]) )
  52.              (mapc '(lambda (pair)
  53.                             [newDictionary at (car pair) (cdr pair)])
  54.                    (car elements))
  55.              newDictionary))
  56. )]
  57.     
  58. [{MetaDictionary} new 'name 'Dictionary
  59.     'superClass        {Collection}
  60.         'instanceVariables    '(aSymbol)
  61.         'methods        '(
  62. at ((key . value)
  63.     (if value
  64.             (putprop #IaSymbol (car value) key)
  65.             ;;ELSE
  66.             (getprop #IaSymbol key)))
  67.  
  68. do ((aLambda)
  69.     (let ( (pl (plist #IaSymbol)) )
  70.              (while pl
  71.                     (funcall aLambda (nextl pl) (nextl pl))))
  72.         self)
  73.  
  74. size (()    (/ (length (plist #IaSymbol)) 2))
  75. )]
  76.      
  77.