I figured that since Emacs Lisp and Common Lisp seemed so closely related syntax wise, I could just follow the example code I found on RosettaCode, but it turns out that I was wrong.
The code in question looks like this:
(defun print-name (&key first (last "?"))
(princ last)
(when first
(princ ", ")
(princ first))
(values))
And according to RosettaCode it should do the following:
> (print-name)
?
> (print-name :first "John")
?, John
> (print-name :last "Doe")
Doe
> (print-name :first "John" :last "Doe")
Doe, John
Now, here's the thing; whenever I try to run that function in my ELisp interpreter, I get the following error:
*** Eval error *** Wrong number of arguments: (lambda (&key first (last "?")) (princ la\
st) (if first (progn (princ ", ") (princ first))) (values)), 0
I'm not routined enough in lisp to know what that's supposed to mean, and no amount of Googling has lead me any closer to an answer.
So what's the correct way of doing this in Emacs Lisp?