Programmatically name a struct
Programmatically name a struct
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
Not sure if I understood you correctly, but
would do it?
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")
Re: Programmatically name a struct
Thanks! The only change I made was to use the symb function from On Lisp since I had that code already.