From: Onay
Subject: how is a generic function accessed in compiled lisp code?
Date: 
Message-ID: <42878c4b$0$14733$9b4e6d93@newsread4.arcor-online.net>
having some function versions like

(defgeneric f)

(defmethod f ((x number)) ...)
(defmethod f ((x string)) ...)
(defmethod f ((x list)) ...)
(defmethod f ((x vector)) ...)
...

how does lisp code (compiled!) access a specific version of f?
Let's assume the argument types are unknown at compile-time. So we have

(f 1.0) -> (defmethod f ((x number)) ...))

Is it by 
(i)  hash table lookup ?
(ii) tree lookup ?

-- 
(+::+) oni (+::+)
(I already try to be as amusing as possible, my master!)

From: Pascal Costanza
Subject: Re: how is a generic function accessed in compiled lisp code?
Date: 
Message-ID: <3ephd2F49vc2U1@individual.net>
Onay wrote:
> having some function versions like
> 
> (defgeneric f)
> 
> (defmethod f ((x number)) ...)
> (defmethod f ((x string)) ...)
> (defmethod f ((x list)) ...)
> (defmethod f ((x vector)) ...)
> ...
> 
> how does lisp code (compiled!) access a specific version of f?
> Let's assume the argument types are unknown at compile-time. So we have
> 
> (f 1.0) -> (defmethod f ((x number)) ...))
> 
> Is it by 
> (i)  hash table lookup ?
> (ii) tree lookup ?

A combination of several implementation strategies. If there's only one 
method defined, and all specializers are the "class" t, then the method 
is simply directly invoked. If some of the specializers are not t, there 
is first a typecheck and then again, the method is directly invoked if 
it is applicable.

If more methods are defined, it depends on various measures what can be 
done. A good overview can be found in 
http://www2.parc.com/csl/groups/sda/publications/papers/Kiczales-Andreas-PCL/

(It's a paper from 1991, but I don't believe that implementation 
strategies have fundamentally changed since then.)


Pascal

-- 
2nd European Lisp and Scheme Workshop
July 26 - Glasgow, Scotland - co-located with ECOOP 2005
http://lisp-ecoop05.bknr.net/
From: Pascal Bourguignon
Subject: Re: how is a generic function accessed in compiled lisp code?
Date: 
Message-ID: <87y8ag2wij.fsf@thalassa.informatimago.com>
Onay  <·····@gmx.net> writes:

> having some function versions like
>
> (defgeneric f)
>
> (defmethod f ((x number)) ...)
> (defmethod f ((x string)) ...)
> (defmethod f ((x list)) ...)
> (defmethod f ((x vector)) ...)
> ...
>
> how does lisp code (compiled!) access a specific version of f?
> Let's assume the argument types are unknown at compile-time. So we have
>
> (f 1.0) -> (defmethod f ((x number)) ...))
>
> Is it by 
> (i)  hash table lookup ?
> (ii) tree lookup ?

It's implementation dependant. 
(Check the source of your favorite implementation).


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
Grace personified,
I leap into the window.
I meant to do that.
From: Paul Dietz
Subject: Re: how is a generic function accessed in compiled lisp code?
Date: 
Message-ID: <d6accn$77q$1@avnika.corp.mot.com>
Pascal Bourguignon wrote:
> Onay  <·····@gmx.net> writes:

>>Is it by 
>>(i)  hash table lookup ?
>>(ii) tree lookup ?
> 
> 
> It's implementation dependant. 
> (Check the source of your favorite implementation).

What's more, it's possible that an implementation can allow
you to control the implementation strategy, or even define
new ones, if it supports additional specializations of the
class generic-function (aside from standard-generic-function)
(and similarly for specializations of method aside from
standard-method).

	Paul