From: Vladimir Zolotykh
Subject: values as declaration specifier
Date: 
Message-ID: <3BF3FDB3.76E6CA6A@eurocom.od.ua>
Would you mind to say few words about

(proclaim '(declaration values))
;;;.....
(defgeneric foo (bar)
  (declare (values one-thing another))
  (:method :after ((bar bar))
    ;; ...
    ))
Does such declarations affect generated code ?

Also, Is it permissible to define :after method before the primary one ?

-- 
Vladimir Zolotykh                         ······@eurocom.od.ua

From: Pierre R. Mai
Subject: Re: values as declaration specifier
Date: 
Message-ID: <87vggbu41x.fsf@orion.bln.pmsf.de>
Vladimir Zolotykh <······@eurocom.od.ua> writes:

> Would you mind to say few words about
> 
> (proclaim '(declaration values))
> ;;;.....
> (defgeneric foo (bar)
>   (declare (values one-thing another))
>   (:method :after ((bar bar))
>     ;; ...
>     ))
> Does such declarations affect generated code ?

No.  Since the compiler couldn't possibly know the meaning of the
newly introduced declaration, it can't affect it meaningfully,
either.  This mechanism is intended in order to introduce declarations
as valid, so that the compiler/interpreter can ignore them, without
producing warnings, etc.  So from the POV of the compiler/interpreter
these declarations are really no-ops.  But they can be meaningfully
interpreted by other tools, e.g. you could e.g. produce documentation
from them by walking over your source-code and collecting all values
declarations, etc.

*BUT*:  For historical reasons, CMU CL has its own non-standard 
cl:values declaration, that allows the user to specify the types of 
the values returned from a form, i.e.

(let ((x 1))
  (declare (type fixnum x) (values fixnum))
  (+ x 4))

is equivalent to

(let ((x 1))
  (declare (type fixnum x))
  (the fixnum (+ x 4)))

Similarly

(defun foo (x y)
  (declare (values fixnum))
  ... large function body ...)

is equivalent to

(defun foo (x y)
  (the fixnum
    ... large function body ...))

It would have been much better if this declaration would have been
called ext:values, but it wasn't, and now it is too late to do much
about it.  It's often IMHO preferable to use the standard ftype
declaration, in a declaim, e.g.

(declaim (ftype (function (fixnum fixnum) fixnum) foo))
(defun foo (x y)
  (declare (type fixnum x y))
  ... large function body ...)

In order to use the non-standard cl:values declaration in code,
without causing spurious warnings in other implementations, you can do

(proclaim '(declaration values))

or

(declaim (declaration values))

to cause those implementations to silently ignore the declarations,
instead of issuing warnings.

> Also, Is it permissible to define :after method before the primary one ?

Yes.  You only have to ensure that when the GF is invoked at least one
applicable primary method is defined.  The order in which you define
them doesn't matter.

Regs, Pierre.

-- 
Pierre R. Mai <····@acm.org>                    http://www.pmsf.de/pmai/
 The most likely way for the world to be destroyed, most experts agree,
 is by accident. That's where we come in; we're computer professionals.
 We cause accidents.                           -- Nathaniel Borenstein
From: Vladimir Zolotykh
Subject: Re: values as declaration specifier
Date: 
Message-ID: <3BF4CAE6.34B8BC97@eurocom.od.ua>
Thank you Pierre, quite sufficient.

-- 
Vladimir Zolotykh                         ······@eurocom.od.ua