Monday, January 23, 2006

apply'ing a list

I was wanting to create a convenience function for a class, and wanted to pass along &key parameters to the make-instance function. I couldn't figure out how to use a &rest argument, which puts everything in a list, and I need to get the keywords. My first pass was to use a macro:

(defmacro make-routing-table (&rest args)
`(make-instance 'routing-table ,@args))

worked, but ugly... much better is:

(defun make-routing-table (&rest args)
(apply #'make-instance 'routing-table args))

this from norvig.


Post a Comment

<< Home