From: Yang, Chul-Woong
Subject: Declaration question
Date: 
Message-ID: <yHf%b.133121$S3.1459957@news.bora.net>
Hi.

I'm reading 'OOP in CL' by S.Keene.
At chapter 11, She wrote code like belows.

(defclass....)
...
(defgeneric read-next-element (input-stream)
  (declare (values element eof-p))
   ...

and she describes above 'declare' as
"You will notice that we declare the returned values of generic
functions in several defgeneric forms. This is a convenient way to
document part of the contract of the generic function - the expected
returned values. Although CL does not specify 'values' as a recognized
declaration specifier, we can make it one by proclaiming 'values' as a
declaration as follows:
  (proclaim '(declaration values))
"

With my limited study, above declare statements seems to do nothing
particluar, because 9.2 of CLTL2 said 'declaration' means nonstandard
declaration name and just used in supressing compiler warnings.
Then, is above declaration just for documenting reason?
Or CL can generate warnings if programmer forget returning value in
method read-next-element?
Am I missing something? Any insights will be grateful. TIA.

Yang, Chul-Woong
······@aratech.co.kr

From: Barry Margolin
Subject: Re: Declaration question
Date: 
Message-ID: <barmar-290BB7.00493326022004@comcast.ash.giganews.com>
In article <·······················@news.bora.net>,
 "Yang, Chul-Woong" <······@aratech.co.kr> wrote:

> Hi.
> 
> I'm reading 'OOP in CL' by S.Keene.
> At chapter 11, She wrote code like belows.
> 
> (defclass....)
> ...
> (defgeneric read-next-element (input-stream)
>   (declare (values element eof-p))
>    ...
> 
> and she describes above 'declare' as
> "You will notice that we declare the returned values of generic
> functions in several defgeneric forms. This is a convenient way to
> document part of the contract of the generic function - the expected
> returned values. Although CL does not specify 'values' as a recognized
> declaration specifier, we can make it one by proclaiming 'values' as a
> declaration as follows:
>   (proclaim '(declaration values))
> "
> 
> With my limited study, above declare statements seems to do nothing
> particluar, because 9.2 of CLTL2 said 'declaration' means nonstandard
> declaration name and just used in supressing compiler warnings.
> Then, is above declaration just for documenting reason?

Yes, that's precisely what she said in the text: "a convenient way to 
document part of the contract".

> Or CL can generate warnings if programmer forget returning value in
> method read-next-element?

There could be some implementations that recognize the declaration and 
do something useful with it.  But the language spec doesn't require this.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
From: Christophe Rhodes
Subject: Re: Declaration question
Date: 
Message-ID: <sqr7wi2sa5.fsf@lambda.dyndns.org>
Barry Margolin <······@alum.mit.edu> writes:

> In article <·······················@news.bora.net>,
>  "Yang, Chul-Woong" <······@aratech.co.kr> wrote:
>>   (proclaim '(declaration values))
>> 
>> With my limited study, above declare statements seems to do nothing
>> particluar, because 9.2 of CLTL2 said 'declaration' means nonstandard
>> declaration name and just used in supressing compiler warnings.
>> Then, is above declaration just for documenting reason?
>
> Yes, that's precisely what she said in the text: "a convenient way to 
> document part of the contract".

It's rather bad luck that this was (later, I presume, given that
Keene's book was published in 1989) defined by ANSI to invoke
undefined behaviour (CLHS 11.1.2.1.2, point 6).  Maybe the moral is
that it's safe for Keene, but don't try it at home.

Christophe
-- 
http://www-jcsu.jesus.cam.ac.uk/~csr21/       +44 1223 510 299/+44 7729 383 757
(set-pprint-dispatch 'number (lambda (s o) (declare (special b)) (format s b)))
(defvar b "~&Just another Lisp hacker~%")    (pprint #36rJesusCollegeCambridge)
From: Kalle Olavi Niemitalo
Subject: Re: Declaration question
Date: 
Message-ID: <87wu6ajlqq.fsf@Astalo.kon.iki.fi>
Barry Margolin <······@alum.mit.edu> writes:

> There could be some implementations that recognize the declaration and 
> do something useful with it.  But the language spec doesn't require this.

CMUCL recognizes VALUES declarations.  I don't know if they work
in DEFGENERIC, though.