Classes of functions?

Discussion of Common Lisp
Post Reply
abvgdeika
Posts: 20
Joined: Mon Jun 06, 2011 10:59 pm

Classes of functions?

Post by abvgdeika » Wed Nov 21, 2012 10:01 am

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.
To understand LISP, you must first understand LISP.

Konfusius
Posts: 62
Joined: Fri Jun 10, 2011 6:38 am

Re: Classes of functions?

Post by Konfusius » Wed Nov 21, 2012 5:01 pm

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)

edgar-rft
Posts: 226
Joined: Fri Aug 06, 2010 6:34 am
Location: Germany

Re: Classes of functions?

Post by edgar-rft » Wed Nov 21, 2012 11:41 pm

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

Post Reply