Hi,

I recently experimented with docstrings, and I stumbled over not being
able to define a function which only has a docstring as body:


    (define (foo)
      "bar")
    
    (procedure-documentation foo)
    ⇒ #f


Adding a form makes the string act as docstring:


    (define (foo)
      "bar"
      #f)
    
    (procedure-documentation foo)
    ⇒ "bar"


I feel that this is inconsistent, which hurts even more, because it
breaks for the simplest showcase of docstrings.


My use case for using docstrings like this is that when I start writing
a function, I begin with the docstring. There I explain what I want to
do. Then I commit. Then I implement the function.

We already discussed in #guile @ freenode, that it is simple to add a
dummy-body to make the docstring work. To me that feels like a
cludge. And I was asked to move the discussion here.


A reason for not wanting a string as the only part of the body to be
seen as docstring are that this would make it harder to write
functions which only return a string without giving them their return
value as docstring. This would then require this:

    (define (foo)
      #f
      "bar")


I think it would be more consistent to have the first form of the body
double as a docstring if it is a string.

The current behaviour is that if the first form in the function is a
string, it is not part of the body - except if the body would
otherwise be empty.


What do you think?


Best wishes,
Arne

Reply via email to