[parenscript-devel] lisp-like lambda lists (keyword, option, and rest arguments)
Red Daly
reddaly at stanford.edu
Mon Jul 30 22:22:17 UTC 2007
In my local version I have added support for very Lispy lambda lists
with keyword, optional, and &rest arguments. Is this a feature we
should add to the language?
The Javascript convention for passing named arguments is to have an
options variable that functions as a hash table for keywords. I use
this convention for passing keyword arguments in Parenscript. Also,
when a quoted symbol (e.g. a keyword) is found in a function call, the
an options object is constructed.
Here are a few examples
(defun name (first last &key (prefix "Ms.") (middle
""))
(return (+ prefix " " first " " middle " " last)))
=>
function name (first last options) {
options.prefix = options.prefix === undefined ? "Ms." : options.prefix;
options.middle = options.middle === undefined ? " " : options.middle;
return prefix + " " + first " " + middle + " " + last;
}
(defun vote (&optional (times 1)) ...)
=>
function vote (times) {
times = times === undefined ? 1 : times;
...}
(defun append (&rest lists) ...)
=>
function append()
{ lists = arguments.slice(0); ...}
(name "John" "Cunningham" :prefix "Mr." :middle "Appleton")
=> name("John", "Cunningham", { prefix : "Mr." , middle : "Appleton" })
I like having the extra lambda list features available in my own code.
Should we add this to Parenscript?
-Red
More information about the parenscript-devel
mailing list