[parenscript-devel] lisp-like lambda lists (keyword, option, and rest arguments)

Red Daly reddaly at stanford.edu
Wed Aug 1 06:46:43 UTC 2007


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 at 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 at common-lisp.net
>> http://common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel
>>
>>     
> _______________________________________________
> parenscript-devel mailing list
> parenscript-devel at common-lisp.net
> http://common-lisp.net/cgi-bin/mailman/listinfo/parenscript-devel
>   




More information about the parenscript-devel mailing list