Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!daver!tscs!tct!chip From: chip@tct.uucp (Chip Salzenberg) Newsgroups: comp.lang.c++ Subject: Re: Implementing LISP in C++ (type discrimination) Message-ID: <27E181D5.72D5@tct.uucp> Date: 16 Mar 91 02:24:21 GMT References: <1991Mar12.221015.22144@aero.org> <1991Mar13.145107.19724@linus.mitre.org> <1991Mar13.214542.13779@aero.org> Organization: Teltronics/TCT, Sarasota, FL Lines: 30 According to jordan@aero.org (Larry M. Jordan): >... a generic mark function 'void mark(Node*)' which knows how to >traverse LISP structures, as I indicated before in a non recursive >way, saving backpointer when chasing car's and cdr's and restoring >pointers when unwinding. Writing such a generic mark function seems >to require doing a case analysis, doesn't it? In general, an "isKindOf()" test can almost always be replaced by a virtual function. For example: switch (p->type()) { case Cons: do_cons_thing((Cons *)p); break; case String: do_string_thing((String *)p); break; } can be replaced with a virtual do_thing() function, with implementations Cons::do_thing() and String::do_thing(). Then the above code becomes simply: p->do_thing(); >there are a lot of calls to virtual methods during the marking phase. >How can this be as efficient as an up front case analysis?! A switch() is typically a table lookup. So is a virtual function lookup. Any more questions? -- Chip Salzenberg at Teltronics/TCT , "Most of my code is written by myself. That is why so little gets done." -- Herman "HLLs will never fly" Rubin