views:

117

answers:

2

I.e. transferring the state from one object to another object, which shares some (but not all) of the first object's members.

I'm not applying this question to any real-life problem yet, but I guess I'm asking it to get a feel for the differences between the problem-solving approach in LISP as opposed to object-oriented languages like C#.

+1  A: 

That's pretty simple.

You just write a small function that looks at which slots the object's classes have in common (with the help of the Meta-Object Protocol) and copies their values. 10 lines max.

skypher
Looking at the MOP, it looks like COMPUTE-SLOTS is the routine needed, but I'm not sure how that would be used - I applied to a DEFCLASS class and an instantiation of it in CLISP, and errors resulted. :-/
Paul Nathan
Not sure if you're still looking for an answer, but here's how to use COMPUTE-SLOTS in CLISP: http://paste.lisp.org/display/116008 But you probably want to use CLASS-SLOTS instead. Then use SLOT-DEFINITION-NAME to get the slot's name.
skypher
+1  A: 

Just as an object is an instance of a class, a class is also an object, which is an instance of the (meta)class "class". You can ask each of your classes for the list of it's slot definitions and compare the two lists to find the commonalities. http://www.lisp.org/mop/concepts.html

mazemaster225
Thanks for the link. Very comprehensive.
jonathanconway