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

Re: [Q] Dylan to Java/JVM compiler?



Hello!

In article <m3k83r7e3z.fsf@localhost.localdomain>,
Lieven Marchand  <mal@wyrd.be> wrote:
>[... evolved from a discussion of declaring methods on make in Dylan,
>     specialized on single classes ...]


>BTW, why does LispWorks complain about the equivalent CL code? The
>Hyperspec specifically allows users to augment the MAKE-INSTANCE
>generic function.

>CL-USER 8 > (defmethod make-instance ((class (eql (find-class
>'abstract))) &rest args)
>              (apply #'make-instance 'concrete args))

>Error: Defining method #<STANDARD-METHOD MAKE-INSTANCE NIL ((EQL
>#<STANDARD-CLASS ABSTRACT 21151714>)) 204D8444> visible from packages
>COMMON-LISP.
>  1 (continue) Define it anyway.
>  2 Discard the new method.
>  3 (abort) Return to level 0.
>  4 Return to top loop level 0.

>It works as expected when you choose restart 1.

Dunno. sbcl accepts the equivalent of that:

(defclass a () ())
(defclass b () ())

(defmethod make-instance ((class (eql (find-class 'a))) &key &allow-other-keys
                          &rest args)
  (apply #'make-instance 'b args))

(It spits out many optimization warnings though)

Now,

(let ((x (make-instance 'a)))
  (class-of x))

yields
#<STANDARD-CLASS A>

while

(let ((x (make-instance (find-class 'a))))
  (class-of x))

yields
#<STANDARD-CLASS B>

So to achieve what was intended, you'd also have to specify
(defmethod make-instance ((class (eql 'a)) ...)
  ...)

Looks like an application for a small macro: define a generic
where one argument position is specialized eql a symbol *and*
the corresponding class.

Kind regards,

Hannah.



References: