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
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/
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 ***
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.