LISP – Keyword Parameters

  • Post author:
  • Post category:LISP
  • Post comments:1 Comment
LISP - Keyword Parameters

This topic is about LISP – Keyword Parameters.

Keyword parameters allow you to specify which values go with which particular parameter.

It is indicated using the &key symbol.

When you send the values to the function, you must precede the values with :parameter-name.

The following example illustrates the concept.

Example

Create a new source code file named main.lisp and type the following code in it.

(defun show-members (&key a b c d ) (write (list a b c d)))
(show-members :a 1 :c 2 :d 3)
(terpri)
(show-members :a 'p :b 'q :c 'r :d 's)
(terpri)
(show-members :a 'p :d 'q)
(terpri)
(show-members :a 1 :b 2)

When you execute the code, it returns the following result −

(1 NIL 2 3)
(P Q R S)
(P NIL NIL Q)
(1 2 NIL NIL)

To know more, Click Here

This Post Has One Comment

Leave a Reply