chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] Question about COOPS, generic methods, and modules


From: Peter Bex
Subject: Re: [Chicken-users] Question about COOPS, generic methods, and modules
Date: Thu, 23 Sep 2010 09:15:26 +0200
User-agent: Mutt/1.4.2.3i

On Wed, Sep 22, 2010 at 09:06:33PM -0400, Taylor Venable wrote:
> #;1> (use coops)
> #;2> (load "coops-test-2.scm")
> Note: implicitly defining generic-procedure: lols
> #;3> (import foo)
> #;4> (define instance (make <a-class>))
> #;5> (lols instance)
> 5
> #;6> (load "coops-test-2.scm")
> ; loading coops-test-2.scm ...
> Note: implicitly defining generic-procedure: lols
> #;7> (lols instance)
> 
> Error: (lols) no method defined for given argument classes: (#<coops
> standard-class `<a-class>'>)
> 
>         Call history:
> 
>         <syntax>          (lols instance)
>         <eval>    (lols instance)       <--

That kind of makes sense.  I have no idea how coops works, but
loading the file again is more or less the same as typing in every
expression in the file.

See this session:

#;1> (use coops)
#;2> (define-class foo)
#;3> (define old-foo foo)
#;4> (define-method (bar (x foo)) (print "hi"))
Note: implicitly defining generic-procedure: bar
#;5> (bar (make foo))
hi
#;6> (define-class foo)
#;7> (bar (make foo))
Error: (bar) no method defined for given argument classes: (#<coops 
standard-class `foo'>)
....
#;8> (bar (make old-foo))
hi

As you can see, defining a new class creates a completely new class
object which in this case happens to be bound to the same
identifier (foo), and happens to be structurally identical, but it
is a completely new class.  The bar method is defined only for
the class I defined at the start, as you can see at prompt #8.

Cheers,
Peter
-- 
http://sjamaan.ath.cx
--
"The process of preparing programs for a digital computer
 is especially attractive, not only because it can be economically
 and scientifically rewarding, but also because it can be an aesthetic
 experience much like composing poetry or music."
                                                        -- Donald Knuth



reply via email to

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