Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

What is a generic function?


It's a function that has one or more required arguments, and a set of methods. Each method has a class (or an EQL specifier) associated with each argument. When the generic function is called, the best method for which each actual parameter is in the corresponding argument's class is invoked. Think of it like a method in ordinary OO, but it can dispatch on multiple arguments.

There's also some interesting stuff on top of this (method combinations) that allow multiple methods to be invoked and their results combined.

https://en.wikipedia.org/wiki/Generic_function#In_Common_Lis...

http://clhs.lisp.se/Body/07_f.htm


For an interesting application, see how https://github.com/joaotavora/snooze#rationale maps generic functions to HTTP/REST.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: