William James
8/12/2015 10:51:00 PM
Pascal J. Bourguignon wrote:
> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>
> > Common-Lisp has the notion of an object that can be called, functions
> > being one example, generic functions another (and IIUC symbols also are
> > callable).
> >
> > AFAICT the Common-Lisp standard does not provide a standard way to build
> > such objects in general: you can't define your own kind of
> > callable object.
> >
> > Do some Common-Lisp implementations offer a way to define your own
> > callable objects? If so, which ones, and what kind of primitive do they
> > provide to do that?
>
> Yes, it's done with the MOP and CLOS.
>
> I don't know the details, but basically you can define your own
> subclasses of closer-mop:FUNCALLABLE-STANDARD-OBJECT.
Gauche Scheme:
(define-method object-apply ((v <vector>) (i <integer>))
(vector-ref v i))
(#(a b c d e) 4)
===>
e
--
He has nothing but kind sentiments for those who would destroy his home and
family.... He is universally tolerant.... If he has any principles, he keeps
them well concealed.... He is, to the extent of his abilities, exactly like
the next citizen, who, he trusts, is trying to be exactly like him: a faceless,
characterless putty-man. --- Father Feeney; "Should Hate Be Outlawed?"