How would a LISP developer solve the problem that AutoMapper solves in .NET?
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 a开发者_开发知识库ny 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#.
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
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.
精彩评论