r***@gmail.com
2020-02-07 18:35:28 UTC
Is there a concise way to make a struct with an array of structs?
I have found the following works although it is very verbose.
(defstruct lottery-ticket
(purchased ‘T)
(number ‘16384))
(defstruct tickets-array
(number-of-tickets 1000000)
(tickets))
(setf my-tickets (make-tickets-array))
(setf (tickets-array-tickets my-tickets) (make-array ‘10 :initial-element (make-lottery-ticket)))
Now I can confirm tickets-array-tickets is an array
(arrayp (tickets-array-tickets my-tickets))
T
I would have preferred to set up the array inside of the defstruct for tickets-array. Is that possible?
Thank you.
I have found the following works although it is very verbose.
(defstruct lottery-ticket
(purchased ‘T)
(number ‘16384))
(defstruct tickets-array
(number-of-tickets 1000000)
(tickets))
(setf my-tickets (make-tickets-array))
(setf (tickets-array-tickets my-tickets) (make-array ‘10 :initial-element (make-lottery-ticket)))
Now I can confirm tickets-array-tickets is an array
(arrayp (tickets-array-tickets my-tickets))
T
I would have preferred to set up the array inside of the defstruct for tickets-array. Is that possible?
Thank you.