1.

What Is Meant By Keyword Argument In Lisp?

Answer»

Keyword arguments are function arguments that are passed by keyword, instead of position. Keyword arguments can be mixed with by-position arguments, and default-value EXPRESSIONS can be SUPPLIED for either kind of ARGUMENT:

(define greet

(lambda (GIVEN #:last surname)

(string-append "Hello, " given " " surname)))

 > (greet "John" #:last "Smith") 

"Hello, John Smith"

> (greet #:last "Doe" "John")

"Hello, John Doe"

In above example last is a keyword argument.

Keyword arguments are function arguments that are passed by keyword, instead of position. Keyword arguments can be mixed with by-position arguments, and default-value expressions can be supplied for either kind of argument:

(define greet

(lambda (given #:last surname)

(string-append "Hello, " given " " surname)))

 > (greet "John" #:last "Smith") 

"Hello, John Smith"

> (greet #:last "Doe" "John")

"Hello, John Doe"

In above example last is a keyword argument.



Discussion

No Comment Found