Hi Cle, > ==========================8X========================== > (class +Foo) > # id > > (var N 0) > (var Foos ()) > > (dm nextId> () (set (var: N) (+ (car (var: N)) 1)))
Just a side-note: While this is correct, you could here take advantage of the 'inc' operator: (dm nextId> () (inc (var: N))) > (dm T () > (=: id (pack "Foo#" (nextId> This))) > (conc (var: Foos) (list (cons (: id) This))) > ) > > # (dm foos> () (mapcar '((X) (car X)) (var: Foos))) # *1a* > # (dm foos> () (mapcar '((X) (car X)) (get '`*Class 'Foos))) # *1b* > (dm foos> () (mapcar '((X) (cdr X)) (get '`*Class 'Foos))) # *1c* > > (dm show> () (prinl "Foo id=" (: id))) > > > (show> (new '(+Foo))) > (show> (new '(+Foo))) > (show> (new '(+Foo))) > > # (prinl "Foos: " (mapcar '((X) (prinl X)) (foos> '+Foo))) # *2a* > # (prinl "Foos: " (mapcar '((X) (prinl (type X))) (foos> '+Foo))) # *2b* > (prinl "Foos: " (mapcar '((X) (show> X)) (foos> '+Foo))) # *2c* > > > (show '+Foo) > ==========================8X========================== > ... > If you execute the code as is, an error will issued at *2c*, that the > message 'show>' is not understood. But if > > * I use *1b* and *2a* instead of *1c* and *2c* the correct id stored in > the CAR of every element in the assoc list will be printed. > * I use *1c* and *2b* instead, a type of +Foo will be reported for > every instance held in the CDR of every association. > * However, using *1a* instead of *1b* or *1c* will get me nowhere at > all, despite I think it should have worked :-( > > To summarize, *1a* will not deliver, what I expect, but *1b* and *1c* > seem to return what I want! Asking for the type of every instance held > in the association list *2b* will answer +Foo correctly. But sending a > 'show>' to every instance (*2c*) will repsond with "Bad message". > > So please enlight me, where is my stumble block? What did I wrong? The initial error is the 'conc' in the 'T' method. It concatenates the (id . object) pairs to 'Foos', which is (NIL) in the beginning. So the list has always NIL as its first element. Then, sending the message 'show>' to that NIL gives an error. You could take 'push' or 'queue' instead. I use 'queue' here, because 'push' would reverse the order: (dm T () (=: id (pack "Foo#" (nextId> This))) (queue (var: Foos) (cons (: id) This)) ) But then, of course, 'Foos' has an additional level of nesting. To access the list, you must use 'car' or 'val': (dm foos> () (mapcar cdr (val (var: Foos)))) The complete program would then look like: ==========================8X========================== (class +Foo) # id (var N 0) (var Foos ()) (dm nextId> () (inc (var: N)) ) (dm T () (=: id (pack "Foo#" (nextId> This))) (queue (var: Foos) (cons (: id) This)) ) (dm foos> () (mapcar cdr (val (var: Foos))) ) (dm show> () (prinl "Foo id=" (: id)) ) (show> (new '(+Foo))) (show> (new '(+Foo))) (show> (new '(+Foo))) (prinl "Foos: " (mapcar 'show> (foos> '+Foo))) (show '+Foo) ==========================8X========================== Is this what you intended? Cheers, - Alex -- UNSUBSCRIBE: mailto:picol...@software-lab.de?subject=unsubscribe