From: deech
Subject: Teensy bug with documentation function?
Date: 
Message-ID: <1811e213-1b24-406c-bf3e-f665ee1bb2c8@a29g2000pra.googlegroups.com>
I am using SBCL 1.0.21 with SLIME and noticed the following behavior
yesterday (STYLE-WARNINGs removed):

CL-USER> (defun test () "This function does nothing")
TEST
CL-USER> (documentation 'test 'function)
NIL
CL-USER> (defun test () "This function does nothing" '())
TEST
CL-USER> (documentation 'test 'function)
"This function does nothing"

If I revert the function and rerun documentation the doc-string stays
as-is:

CL-USER> (defun test () "This function does nothing")
TEST
CL-USER> (documentation 'test 'function)
"This function does nothing"

And even more interesting ....

CL-USER> (defun test () "This function does something")
TEST
CL-USER> (documentation 'test 'function)
"This function does nothing"
CL-USER> (defun test () "This function does something" '())
TEST
CL-USER> (documentation 'test 'function)
"This function does something"

-deech

From: Rainer Joswig
Subject: Re: Teensy bug with documentation function?
Date: 
Message-ID: <joswig-FB3B18.16295004112008@news-europe.giganews.com>
In article 
<····································@a29g2000pra.googlegroups.com>,
 deech <············@gmail.com> wrote:

> I am using SBCL 1.0.21 with SLIME and noticed the following behavior
> yesterday (STYLE-WARNINGs removed):
> 
> CL-USER> (defun test () "This function does nothing")
> TEST

In above case the string is not a documentaton, just a form
that will be evaluated.

http://www.lispworks.com/documentation/HyperSpec/Body/03_dk.htm
3.4.11 Syntactic Interaction of Documentation Strings and Declarations


> CL-USER> (documentation 'test 'function)
> NIL

that's fine.

> CL-USER> (defun test () "This function does nothing" '())
> TEST
> CL-USER> (documentation 'test 'function)
> "This function does nothing"

okay.

> 
> If I revert the function and rerun documentation the doc-string stays
> as-is:
> 
> CL-USER> (defun test () "This function does nothing")
> TEST
> CL-USER> (documentation 'test 'function)
> "This function does nothing"

Well, the standard does not say that the documentation
will be removed if none is specified.

This is useful because you can write a function
without documentation and use

  (setf (documentation 'test 'function) "my documentation")

to set the documentation string.

Redefining the function then will not remove the
documentation, when the function does not specify documentation.

> 
> And even more interesting ....
> 
> CL-USER> (defun test () "This function does something")
> TEST
> CL-USER> (documentation 'test 'function)
> "This function does nothing"

That's fine, because above was no documentation string.


> CL-USER> (defun test () "This function does something" '())
> TEST
> CL-USER> (documentation 'test 'function)
> "This function does something"
> 
> -deech

Looks okay, to me...

-- 
http://lispm.dyndns.org/
From: Barry Margolin
Subject: Re: Teensy bug with documentation function?
Date: 
Message-ID: <barmar-65C380.17505104112008@mara100-84.onlink.net>
In article <····························@news-europe.giganews.com>,
 Rainer Joswig <······@lisp.de> wrote:

> In article 
> <····································@a29g2000pra.googlegroups.com>,
>  deech <············@gmail.com> wrote:
> 
> > I am using SBCL 1.0.21 with SLIME and noticed the following behavior
> > yesterday (STYLE-WARNINGs removed):
> > 
> > CL-USER> (defun test () "This function does nothing")
> > TEST
> 
> In above case the string is not a documentaton, just a form
> that will be evaluated.
> 
> http://www.lispworks.com/documentation/HyperSpec/Body/03_dk.htm
> 3.4.11 Syntactic Interaction of Documentation Strings and Declarations

In other words, what you should have written is:

CL-USER> (defun test () "This function returns this string")
TEST
CL-USER> (test)
"This function returns this string"

The rationale for this behavior is that documentation strings were a 
relatively late addition to the language, and they needed to be backward 
compatible.  Since you could write a function like the above before doc 
strings existed, and it would return the string, we needed to retain 
that behavior.

I suppose we could have made the string do double duty, acting as both 
documentation and a form to evaluate, so that either expectation would 
be met.  But functions with no body are pretty unusual, so it hardly 
seems necessary to check for this case and treat it specially.

-- 
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
From: Kaz Kylheku
Subject: Re: Teensy bug with documentation function?
Date: 
Message-ID: <20081104152340.539@gmail.com>
On 2008-11-04, Barry Margolin <······@alum.mit.edu> wrote:
> I suppose we could have made the string do double duty, acting as both 
> documentation and a form to evaluate, so that either expectation would 
> be met.  But functions with no body are pretty unusual, so it hardly 
> seems necessary to check for this case and treat it specially.

The spec could be that a function X of the form

 (defun x (...) "string")

is considered documented and its documentation string consists of the text:

 "A function that returns \"string\""

or some implementation-defined equivalent.