Peter Seibel writes: > I got stuck for the past couple of weeks working on a couple of the > bigger questions but I finally decided it was time to let go and put > up a new version of the FAQ at: > > <http://www.lispniks.com/faq/faq.html>
You could add a link to the PAIP site even if the book is not online. http://www.norvig.com/paip.html > Anyway, comments are always welcome. And remember you can get a rough > idea of what's in the pipeline at: > > <http://www.lispniks.com/faq/staging-faq.html> I just read the question about function overloading. I don't think function overloading is only about adding a parameter to an existing function while keeping old code running. It's more a OO thing, I believe, where you can send one message and have it dispatched to different methods according to the arguments types (or function signature). So, the corresponding feature in Common Lisp is generic functions. (defgeneric foo (arg)) (defmethod foo ((arg integer)) (format t "I've got a whole of ~A item~:*~P~%" arg)) (defmethod foo ((arg ratio)) (format t "I've got a a fraction of ~A item~:*~P~%" arg)) (map nil (function foo) '(0 1 2 1/2 3/4)) I've got a whole of 0 items I've got a whole of 1 item I've got a whole of 2 items I've got a a fraction of 1/2 items I've got a a fraction of 3/4 items Now, the question is that in C++, you can have a different number of arguments to the same function, and still dispatch according to the type of each arguments. In Common Lisp, you cannot have a different number of arguments to the same function, even to the same generic function. But you can have a variable number of arguments: (defgeneric foo (arg &optional flag)) (defmethod foo ((arg integer) &optional flag) (format t (if flag "~A is an integer~%" "I've got a whole of ~A item~:*~P~%") arg)) (defmethod foo ((arg ratio) &optional flag) (format t (if flag "~A is a ratio~%" "I've got a a fraction of ~A item~:*~P~%") arg)) (progn (map nil (function foo) '(0 1 2 1/2 3/4)) (map nil (function foo) '(0 1 2 1/2 3/4 0 1 2 1/2 3/4) '(t t t t t nil nil nil nil nil))) I've got a whole of 0 items I've got a whole of 1 item I've got a whole of 2 items I've got a a fraction of 1/2 items I've got a a fraction of 3/4 items 0 is an integer 1 is an integer 2 is an integer 1/2 is a ratio 3/4 is a ratio I've got a whole of 0 items I've got a whole of 1 item I've got a whole of 2 items I've got a a fraction of 1/2 items I've got a a fraction of 3/4 items -- __Pascal Bourguignon__ http://www.informatimago.com/ PUBLIC NOTICE AS REQUIRED BY LAW: Any use of this product, in any manner whatsoever, will increase the amount of disorder in the universe. Although no liability is implied herein, the consumer is warned that this process will ultimately lead to the heat death of the universe. _______________________________________________ Gardeners mailing list [email protected] http://www.lispniks.com/mailman/listinfo/gardeners
