[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Docstring as only form in a function

From: Arne Babenhauserheide
Subject: Docstring as only form in a function
Date: Thu, 20 Feb 2014 17:59:40 +0100
User-agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (Gojō) APEL/10.8 Emacs/24.3 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO)


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)
    (procedure-documentation foo)
    ⇒ #f

Adding a form makes the string act as docstring:

    (define (foo)
    (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)

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,

reply via email to

[Prev in Thread] Current Thread [Next in Thread]