Classes of functions?

Discussion of Common Lisp

Classes of functions?

Postby 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.
abvgdeika
 
Posts: 20
Joined: Mon Jun 06, 2011 10:59 pm

Re: Classes of functions?

Postby 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)
Konfusius
 
Posts: 62
Joined: Fri Jun 10, 2011 6:38 am

Re: Classes of functions?

Postby 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
edgar-rft
 
Posts: 161
Joined: Fri Aug 06, 2010 6:34 am
Location: Germany


Return to Common Lisp

Who is online

Users browsing this forum: No registered users and 2 guests

cron