defstruct
defstruct(s_names_slot1[s_slot2...] ) =>t
Description
Creates a defstruct, a named structure that is a collection of one or more variables.
Defstructs can have slots of different types that are grouped together under a single name for handling purposes. They are the equivalent of structs in C. The defstruct form also creates an instantiation function, named make_<name> where name is the structure name supplied to defstruct. This constructor function takes keyword arguments: one for each slot in the structure. Once created, structures behave just like disembodied property lists.
Structures can contain instances of other structures; therefore one needs to be careful about structure sharing. If sharing is not desired, a special copy function can be used to generate a copy of the structure being inserted. The defstruct form also creates a function for the given defstruct called copy_<name>. This function takes one argument, an instance of the defstruct. It creates and returns a copy of the given instance. An example appears after the description of the other defstruct functions.
Arguments
Value Returned
Examples
Returns the value associated with a slot of an instance.
defstruct(myStruct slot1 slot2 slot3)
struct = make_myStruct(?slot1 "one" ?slot2 "two" ?slot3 "three")
=>t
struct->slot1
=> "one"
Modifies the value associated with a slot of an instance.
struct->slot1 = "new"
=> "new"
Returns a list of the slot names associated with an instance.
struct->?
=> (slot3 slot2 slot1)
Returns a property list (not a disembodied property list) containing the slot names and values associated with an instance.
struct->??
=> (slot3 "three" slot2 "two" slot1 "new")
Related Topics
Return to top