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
Hi Red,
That looks awesome. I gave a though to adding something like this, but as usual I assumed it would be hard and involve hacks. You proved me wrong; I really like your implementation. Is there any effect on plain-vanilla lambda lists? If not, then I say go ahead and push it.
Vladimir
On 7/30/07, Red Daly reddaly@stanford.edu wrote:
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
parenscript-devel mailing list parenscript-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel
My changes are now synced up with the repository. Feel free to play around with the latest and greatest.
You might notice that the function toArray() is not defined, required for &rest processing. toArray is simply..
(defun to-array (array-like) (let ((result (array))) (dotimes (i array-like.length) (setf (aref array i) (aref array-like i)))))
-Red
Vladimir Sedach wrote:
Hi Red,
That looks awesome. I gave a though to adding something like this, but as usual I assumed it would be hard and involve hacks. You proved me wrong; I really like your implementation. Is there any effect on plain-vanilla lambda lists? If not, then I say go ahead and push it.
Vladimir
On 7/30/07, Red Daly reddaly@stanford.edu wrote:
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
parenscript-devel mailing list parenscript-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel
parenscript-devel mailing list parenscript-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel
Red Daly reddaly@stanford.edu writes:
My changes are now synced up with the repository. Feel free to play around with the latest and greatest.
You might notice that the function toArray() is not defined, required for &rest processing. toArray is simply..
Having &rest is really awesome. . .
(defun to-array (array-like) (let ((result (array))) (dotimes (i array-like.length) (setf (aref array i) (aref array-like i)))))
Yet another reason to have a delayed "include this function iff it is used" option . . . which is my vote for the next awesome feature ;-)
[...]
I added code to do the to-array stuff in-line. That eliminates the need for to-array as a function, but it also saves some copying and consing time since we know the number of effective-args at compile-time.
Vladimir
On 8/1/07, Red Daly reddaly@stanford.edu wrote:
My changes are now synced up with the repository. Feel free to play around with the latest and greatest.
You might notice that the function toArray() is not defined, required for &rest processing. toArray is simply..
(defun to-array (array-like) (let ((result (array))) (dotimes (i array-like.length) (setf (aref array i) (aref array-like i)))))
-Red
Vladimir Sedach wrote:
Hi Red,
That looks awesome. I gave a though to adding something like this, but as usual I assumed it would be hard and involve hacks. You proved me wrong; I really like your implementation. Is there any effect on plain-vanilla lambda lists? If not, then I say go ahead and push it.
Vladimir
On 7/30/07, Red Daly reddaly@stanford.edu wrote:
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
parenscript-devel mailing list parenscript-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel
parenscript-devel mailing list parenscript-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel
parenscript-devel mailing list parenscript-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel
parenscript-devel@common-lisp.net