[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Anonymous Generic Function Proposal (Draft 1)
- To: common-lisp-object-system@SAIL.STANFORD.EDU
- Subject: Anonymous Generic Function Proposal (Draft 1)
- From: Dick Gabriel <RPG@SAIL.STANFORD.EDU>
- Date: 01 Sep 87 1300 PDT
There are 3 cases to consider:
1. Purely anonymous generic functions, corresponding to
(function (lambda ...)) in Common Lisp.
2. A set of named generic functions to be used within a particular
body, corresponding to (labels ...) in Common Lisp. An analog
to FLET might be appropriate also.
3. A means of extending a generic function currently defined on a
symbol (name). This corresponds to nothing in Common Lisp.
Here is a proposal, inspired by Guy Steele, which covers case 1:
(generic (lambda ...)
(lambda ...)
(lambda ...)
...))
This special form produces a generic function with the lambda-expressions
as the methods. This is about as similar to the FUNCTION syntax as can
be rationally gotten.
To cover case 2 we define an analog to Common Lisp LABELS, but instead of
functions the user defines methods:
(generic-labels ((foo (...)...)
(bar (...) ...)
(bar (...) ...)
(foo (...)...)
<body>)
At this point it is easy to extend FLET similarly:
(generic-flet ((foo (...)...)
(bar (...) ...)
(bar (...) ...)
(foo (...)...)
<body>)
The simplest means of producing an anonymous recursive generic function is:
(generic-labels ((self (...)...(self...)...)
(self (...)...(self...)...)
...)
#'self)
Notice that the special form FUNCTION will need to be amended in CLtL to
be able to produce a generic function, but this should be a natural fallout
of making a generic function a subtype of FUNCTION.
Handling case 3 is more difficult, because there is no corresponding
Common Lisp form to do a similar thing for functions. A danger is to
inadvertently design a form that will also accomplish the dynamic binding
of a function associated with a symbol.
(with-added-methods ((print (...)...)
(print (...)...)
(read (...)...)
(read (...)...)
(read (...)...))
<body>)
Among the things that could have been included in this proposal is
the ability to have the method functions be able to call each other
without going through the generic function object. However, this obscure
case can be hacked together using add-method etc, and I don't believe
it deserves a special syntax. (It might be so obscure you cannot understand
this description, but that only reinforces my argument.)
-rpg-