According to Functions on GigaMonkeys, Common Lisp supports optional positional parameters via &optional
and the default value can be set arbitrarily.
The default default value is nil
.
(defun function (mandatory-argument &optional optional-argument) ... )
and the default value can be set arbitrarily
(defun function (mandatory-argument &optional (optional-argument "")) ....)
Is there a way of distinguishing the cases where the optional parameter has the default value explicitly passed in vs no value at all?
EDIT: evidently the page I linked explains this.
Occasionally, it's useful to know whether the value of an optional argument was supplied by the caller or is the default value. Rather than writing code to check whether the value of the parameter is the default (which doesn't work anyway, if the caller happens to explicitly pass the default value), you can add another variable name to the parameter specifier after the default-value expression. This variable will be bound to true if the caller actually supplied an argument for this parameter and NIL otherwise. By convention, these variables are usually named the same as the actual parameter with a "-supplied-p" on the end. For example:
(defun foo (a b &optional (c 3 c-supplied-p))
(list a b c c-supplied-p))