Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!usc!zaphod.mps.ohio-state.edu!think.com!linus!linus!mingus!john From: john@mingus.mitre.org (John D. Burger) Newsgroups: comp.lang.misc Subject: Re: bizarre instructions Message-ID: <1991Feb25.194658.3712@linus.mitre.org> Date: 25 Feb 91 19:46:58 GMT Sender: news@linus.mitre.org (News Service) Organization: The MITRE Corporation, Bedford, MA 01730 Lines: 42 Nntp-Posting-Host: mingus.mitre.org hrubin@pop.stat.purdue.edu (Herman Rubin) writes: > I have never seen any language description in which the type of the > result in a replacement statement affected what operation is > performed. In Common Lisp, the assignment operator is SETF. One can write SETF methods specialized on the types of the various entities involved in the assignment, including the value being assigned. For example, imagine that I have implemented PERSON objects, which have a NAME attribute. This is meant to be a string. I retrieve the name of a person with an expression like: (PERSON-NAME P1) and I set the name of a person in the following way: (SETF (PERSON-NAME P1) "fred") As I said, the name of a person is a string, but perhaps, for convenience, I want to be able to do the following: (SETF (PERSON-NAME P1) 'FRED) where FRED is a Lisp symbol, not a string. What I can do is write a SETF method for PERSON-NAME that specializes on the symbol type and turns the symbol into a string. (DEFMETHOD (SETF PERSON-NAME) ((NEW-NAME SYMBOL) (P PERSON)) (SETF (PERSON-NAME P) (SYMBOL-NAME NEW-NAME))) Forget the syntax, the short story is that this method will get called whenever an expression like (SETF (PERSON-NAME X) Y) is evaluated and X is a PERSON and Y is a SYMBOL. -- John Burger john@mitre.org "You ever think about .signature files? I mean, do we really need them?" - alt.andy.rooney