[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] tinyclos and variable argument functions

From: felix winkelmann
Subject: Re: [Chicken-users] tinyclos and variable argument functions
Date: Mon, 4 Apr 2005 08:15:03 +0200

> Hi, I am trying to do something like this, which works in other clos-like
> languages (like GOOPS for guile)
> (require 'tinyclos)
> (define-method (foo (a <top>) (b <top>)) (print "two"))
> (define-method (foo (a <top>)) (print "one"))
> (foo 3)
> -> prints "one"
> (foo 1 2)
> Error: bad argument count - received 3 but expected 2
> If I reverse the way foo is defined, by defining the one before the two,
> then the (foo 3) will give a bad argument count.  I use <top> in this
> example, but it is the same for other classes as well.
> Is this just a limitation of tinyclos or is it a bug in tinyclos?  

It is a limitation. The second definition of foo doesn't have a
congruent  argument lists. I guess this is to allow dynamic redefinition,
but I'd have to dig deeper into the tinyclos implementation to
find out.

>If it is
> a limitation, what do you think is the best way to get around it?  Write a
> macro that looks similar to define-method, but creates a new generic for
> each argument length and stores them all in a vector?  Then return a
> function that first checks the argument length and looks up the right
> generic to apply?

Yes, that would be a solution. But perhaps I can fix tinyclos...


reply via email to

[Prev in Thread] Current Thread [Next in Thread]