Page 1 of 1

Classes of functions?

Posted: Wed Nov 21, 2012 10:01 am
by abvgdeika
When dealing with functions in LISP it is sometimes desirable to handle them differently depending on the number of formal variables. My question: is there any possibility to define classes of functions like
"functions_of_one_variable", "functions_of_two_variables" etc? If this were possible, then one could define common methods e.g. iteration of a function of one variable etc.

Re: Classes of functions?

Posted: Wed Nov 21, 2012 5:01 pm
by Konfusius
If you are looking for a way to determine the lambda list of a function then: yes, it's possible. But its implementation dependent. For example, in Clozure CL you can determine the lambda list with ccl:arglist:
? (ccl:arglist #'mapcar)
->(FUNCTION LIST &REST CCL::MORE-LISTS)

Re: Classes of functions?

Posted: Wed Nov 21, 2012 11:41 pm
by edgar-rft
The old-school way would be using property lists via GET, e.g. tag the symbols of all desired functions with properties like 'one-arg, 'two-args, etc., then write a universal iteration function that reads the properties and behaves accordingly. This works with all implementations, also with the symbols in the CL package.

- edgar