Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!cbnewsl!davel From: davel@cbnewsl.att.com (David Loewenstern) Newsgroups: comp.lang.lisp Subject: Re: Accessing a field of a Lisp structure Message-ID: <1991Apr10.215214.2827@cbnewsl.att.com> Date: 10 Apr 91 21:52:14 GMT References: Distribution: usa Organization: AT&T Bell Labs, Whippany, NJ Lines: 37 In article mzaik@ee.eng.ohio-state.edu (Tahsin Mzaik) writes: >Hello Lisp experts: > >I have a common lisp question: > >I would like to write a macro that can access a particular field >in a structure. > >Example: Let the structure be: > (defstruct test a b c) > > (make-test instance) > >I would like to wite a macro 'access-field' that I can invoke >something like > > (access-field instance 'a) > >in order to access field a of the structure. I have tried the >following, but it does not work: > > (defmacro access-field (instance field) > '(setq (test-,field ,instance) any-value) > ) Try: (defmacro access-field (instance field) `(,(intern (format nil "~A-~A" 'test field)) ,instance)) Note that this will allow (access-field instance a) to work but not, for example (access-field instance (get-slot-name-from-some-wierd-place)) > > >Any ideas? Thanks for any reply.