converting macro parameter name to key parameter
Posted: Sun May 31, 2009 4:34 pm
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:
And wanted to have some nice macros to create unit vectors. I didn't want to write 3 functions like:
because I thought the point of having macros was not repeating functions, so I wanted something that would work more like:
that would expand to:
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:
but I need :X, not |:X|, as in:
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!
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:
Code: Select all
(defstruct 3d-point
(x 0)
(y 0)
(z 0))
Code: Select all
(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))
Code: Select all
(versor x)
Code: Select all
(make-3d-point :x 1.0)
Is there a way to do something like that?
I tried:
Code: Select all
(intern (concatenate 'string ":" (symbol-name (second '(versor x)))))
|:X|
Code: Select all
(car (cons :X 1))
:X
BTW, i'm using sbcl.
Thanks!