Page 1 of 1
Programmatically name a struct
Posted: Tue Jun 26, 2012 7:15 am
by mgcheung
I was wondering if there was a way to create a new struct where the name of the struct is created programmatically. The idea is there is a constant part of the name and then a part of the name the user could specify. My thought would be to do something like (defstruct (symb 'const name) x y), but I know that doesn't work. Is there something like symbol-function for structs?
Re: Programmatically name a struct
Posted: Tue Jun 26, 2012 1:51 pm
by wvxvw
Not sure if I understood you correctly, but
Code: Select all
(defmacro defstruct-x (name &rest rest)
`(defstruct
,(intern
(concatenate 'string "FOO-"
(symbol-name name))) ,@rest))
(defstruct-x person (name "John" :type string))
(make-foo-person :name "James")
would do it?
Re: Programmatically name a struct
Posted: Wed Jun 27, 2012 6:42 am
by mgcheung
Thanks! The only change I made was to use the symb function from On Lisp since I had that code already.