Save data structures directly (not as pointer)
Posted: Sun Feb 08, 2015 5:51 pm
In C(++) its also possible to save datastructures directly (not as pointers).
Is this possible in CL (maybe via libaries)?
for example if I have a struct, that can have different number of dimensions, I would do it this way:
and make the vectors of different size, dependent on the dimension I use, but this is slower than special structs like this:
in c++ I could use generics (templates) to change the object
instead of using pointers
is a similar behaviour possible in CL or would I have to write own macros that work this way
Is this possible in CL (maybe via libaries)?
for example if I have a struct, that can have different number of dimensions, I would do it this way:
Code: Select all
(defstruct mover
(pos nil :type vector)
(vel nil :type vector))
Code: Select all
(defstruct mover2d
px py
vx vy)
(defstruct mover3d
px py pz
vx vy vz)
Code: Select all
template <int S>
struct mover{
int pos[S];
int vel[S];
}
is a similar behaviour possible in CL or would I have to write own macros that work this way
Code: Select all
(my-defstruct-template mover p v)
(macroexpand '(my-defstruct moverxd (mover x x)))
=>(defstruct moverxd
p0 .. px
v0 .. vx)