I have some code that goes essentially like this:
(defparameter *probability* 1
"the probability of the situation being examined")
(defparameter *deck* (make-deck)
"the deck being examined; may be missing some cards")
(defmacro for-each-card ((card-variable
&key ((:deck deck-variable) '*deck*))
&body body)
"Execute BODY once for each card.
Each time:
CARD-VARIABLE is bound to a card from DECK-VARIABLE.
DECK-VARIABLE is bound to the remaining cards, in unspecified order.
*PROBABILITY* is bound to a fraction of its previous value."
...)
The purpose of the last documentation string is to explain the
interface of the macro, and I think the keyword :DECK is more a
part of that interface than the parameter name DECK-VARIABLE is.
So should the docstring refer to the keyword instead?
Yep. Use :DECK in the docstring. That is what is visible in the API.
BTW, isn't this a cute feature of CL. I find myself using it a lot
recently.
Cheers
Marco
Kalle Olavi Niemitalo wrote:
> I have some code that goes essentially like this:
>
> (defparameter *probability* 1
> "the probability of the situation being examined")
>
> (defparameter *deck* (make-deck)
> "the deck being examined; may be missing some cards")
>
> (defmacro for-each-card ((card-variable
> &key ((:deck deck-variable) '*deck*))
> &body body)
> "Execute BODY once for each card.
> Each time:
> CARD-VARIABLE is bound to a card from DECK-VARIABLE.
> DECK-VARIABLE is bound to the remaining cards, in unspecified order.
> *PROBABILITY* is bound to a fraction of its previous value."
> ...)
>
> The purpose of the last documentation string is to explain the
> interface of the macro, and I think the keyword :DECK is more a
> part of that interface than the parameter name DECK-VARIABLE is.
> So should the docstring refer to the keyword instead?
Marco Antoniotti <·······@cs.nyu.edu> wrote in message news:<·················@typhoon.nyu.edu>...
> BTW, isn't this a cute feature of CL. I find myself using it a lot
> recently.
Yeah, I especially like
(defvar *x* ...)
(defun foo (&key ((:x *x*) *x*))
...)
Kalle Olavi Niemitalo wrote:
> I have some code that goes essentially like this:
>
> (defparameter *probability* 1
> "the probability of the situation being examined")
>
> (defparameter *deck* (make-deck)
> "the deck being examined; may be missing some cards")
>
> (defmacro for-each-card ((card-variable
> &key ((:deck deck-variable) '*deck*))
> &body body)
> "Execute BODY once for each card.
> Each time:
> CARD-VARIABLE is bound to a card from DECK-VARIABLE.
> DECK-VARIABLE is bound to the remaining cards, in unspecified order.
> *PROBABILITY* is bound to a fraction of its previous value."
> ...)
>
> The purpose of the last documentation string is to explain the
> interface of the macro, and I think the keyword :DECK is more a
> part of that interface than the parameter name DECK-VARIABLE is.
> So should the docstring refer to the keyword instead?
Definitely.
Pascal
--
Tyler: "How's that working out for you?"
Jack: "Great."
Tyler: "Keep it up, then."
Kalle Olavi Niemitalo <···@iki.fi> writes:
> I have some code that goes essentially like this:
>
> (defparameter *probability* 1
> "the probability of the situation being examined")
>
> (defparameter *deck* (make-deck)
> "the deck being examined; may be missing some cards")
>
> (defmacro for-each-card ((card-variable
> &key ((:deck deck-variable) '*deck*))
> &body body)
> "Execute BODY once for each card.
> Each time:
> CARD-VARIABLE is bound to a card from DECK-VARIABLE.
> DECK-VARIABLE is bound to the remaining cards, in unspecified order.
> *PROBABILITY* is bound to a fraction of its previous value."
> ...)
>
> The purpose of the last documentation string is to explain the
> interface of the macro, and I think the keyword :DECK is more a
> part of that interface than the parameter name DECK-VARIABLE is.
> So should the docstring refer to the keyword instead?
Hmmm, to say that ":DECK is bound to" something doesn't sound right,
and in any case shouldn't macros be documented differently from
functions, along the following lines:
FOR-EACH-CARD (card-variable [ :DECK deck-variable ]) form* [Macro]
Execute the forms once for each card.
Each time:
* card-variable is bound to a card from the value of deck-variable;
* deck-variable (if unsupplied, *DECK*) is bound to the remaining
cards, in unspecified order;
* *PROBABILITY* is bound to a fraction of its previous value;
(card-variable and deck-variable must be symbols).
I don't think it is appropriate to say that a macro has an
interface---it has a syntax.
---Vassil.
--
Vassil Nikolov <········@poboxes.com>
Hollerith's Law of Docstrings: Everything can be summarized in 72 bytes.
Hi
Vassil Nikolov wrote:
> Kalle Olavi Niemitalo <···@iki.fi> writes:
>
>
>>I have some code that goes essentially like this:
>>
>>(defparameter *probability* 1
>> "the probability of the situation being examined")
>>
>>(defparameter *deck* (make-deck)
>> "the deck being examined; may be missing some cards")
>>
>>(defmacro for-each-card ((card-variable
>> &key ((:deck deck-variable) '*deck*))
>> &body body)
>> "Execute BODY once for each card.
>>Each time:
>> CARD-VARIABLE is bound to a card from DECK-VARIABLE.
>> DECK-VARIABLE is bound to the remaining cards, in unspecified order.
>> *PROBABILITY* is bound to a fraction of its previous value."
>> ...)
>>
>>The purpose of the last documentation string is to explain the
>>interface of the macro, and I think the keyword :DECK is more a
>>part of that interface than the parameter name DECK-VARIABLE is.
>>So should the docstring refer to the keyword instead?
>
>
> Hmmm, to say that ":DECK is bound to" something doesn't sound right,
> and in any case shouldn't macros be documented differently from
> functions, along the following lines:
>
> FOR-EACH-CARD (card-variable [ :DECK deck-variable ]) form* [Macro]
>
> Execute the forms once for each card.
> Each time:
> * card-variable is bound to a card from the value of deck-variable;
> * deck-variable (if unsupplied, *DECK*) is bound to the remaining
> cards, in unspecified order;
> * *PROBABILITY* is bound to a fraction of its previous value;
> (card-variable and deck-variable must be symbols).
>
> I don't think it is appropriate to say that a macro has an
> interface---it has a syntax.
I'd say you are right, but the documentation you propose seems
ambiguous to me. It looks to my like you need both :DECK and
DECK-VARIABLE. The issue is that the :DECK keyword is actually the
interface. You do not know what the internal name is (assuming this is
actually in the doc string)
Cheers
--
Marco