Hi,
I'm learning common lisp and this is my first try at writing something useful. I wanted to create some functions and data structures to work with 3d objects. I started with a 3d-point like this:
Is there a way to do something like that?
I tried:
BTW, i'm using sbcl.
Thanks!
I'm learning common lisp and this is my first try at writing something useful. I wanted to create some functions and data structures to work with 3d objects. I started with a 3d-point like this:
(defstruct 3d-point
(x 0)
(y 0)
(z 0))
And wanted to have some nice macros to create unit vectors. I didn't want to write 3 functions like:
(defun versor-x ()
(make-3d-point :x 1.0))
(defun versor-y ()
(make-3d-point :y 1.0))
(defun versor-z ()
(make-3d-point :z 1.0))
because I thought the point of having macros was not repeating functions, so I wanted something that would work more like:
(versor x)
that would expand to:
(make-3d-point :x 1.0)
Now, I'm having a lot of trouble getting it done. The problem is that I can't see a way to access the symbol name (the 'x' in this case) and later use it as a keyword parameter for the make-3d-point function (as ':x').Is there a way to do something like that?
I tried:
(intern (concatenate 'string ":" (symbol-name (second '(versor x)))))
|:X|
but I need :X, not |:X|, as in:
(car (cons :X 1))
:X
And, in a more general sense, am I doing this the right way? Or should I do the 3 function variant? Or something else? Maybe ditch structures, or use them other way?BTW, i'm using sbcl.
Thanks!