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

Issue: FORMAT-COLON-UPARROW-SCOPE



Issue: FORMAT-COLON-UPARROW-SCOPE

References:    CLtL p. 406 and also p. 403

Category:      CLARIFICATION

Edit history:  version 1: Guy Steele, 30 November 1987


Problem description:

Implementations currently differ on the question of what is tested by the
FORMAT command "~:â??".  Some implementations test to see whether any
arguments remain in the sublist for the current iteration step; others test
to see whether any sublists remain.  The text on page 406 is not clear
on this point.


Proposal (FORMAT-COLON-UPARROW-SCOPE:TEST-FOR-REMAINING-SUBLISTS):
~:â?? may be used only if the command it would terminate is ~:{ or ~:@{.
The entire iteration process is terminated if and only if the sublist
that is supplying the arguments for the current iteration step is the
last sublist (in the case of ~:{) or the last FORMAT argument (~:@{).
Note that ~:â?? is *not* equivalent to ~:#â??; the latter terminates the
entire iteration if and only if no arguments remain for the current
iteration step.

Proposal (FORMAT-COLON-UPARROW-SCOPE:TEST-FOR-REMAINING-ARGUMENTS):
~:â?? may be used only if the command it would terminate is ~:{ or ~:@{.
The entire iteration process is terminated if and only if no more arguments
remain for the current iteration step.  Thus ~:â?? is equivalent to ~:#â??,
just as ~â?? is equivalent to ~#â??.


Test Cases/Examples:

(format nil "~:{~@?~:â??...~}" '(("a") ("b")))

Under proposal FORMAT-COLON-UPARROW-SCOPE:TEST-FOR-REMAINING-SUBLISTS
this yields "a...b".

Under proposal FORMAT-COLON-UPARROW-SCOPE:TEST-FOR-REMAINING-ARGUMENTS
this yields "a".


Rationale:

FORMAT-COLON-UPARROW-SCOPE:TEST-FOR-REMAINING-SUBLISTS is desirable
because otherwise there is no way to test whether any sublists remain.
The text on page 406 may be construed to hint at this proposal
indirectly.  To quote Nick Gall:

   If one thinks about the intent of the parenthetical

      (because in the standard case it tests for remaining arguments of
      the current step only)

   one should agree that "a...b" will be returned.  In referring to ~â?? as
   the "standard case", which tests the arguments remaining in the
   current argument sublist, this parenthetical implies that there is
   an `other case', which tests `something else.'  The only `other case'
   discussed is ~:â??, which therefore must test `something else.'  I claim
   that the parentheical makes no sense if we interpret ~:â?? as testing
   the same condition as ~â??.  If they both test the same condition, why
   have the parenthetical explanation?

   If ~:â?? doesn't test the same condition as ~â??, then what does it test?
   I claim that the only test that makes sense is for ~:â?? to test the
   only thing that affects the "entire iteration process:" the number of
   sublists.  When there are no more sublists, "the entire iteration
   process" is terminated.

FORMAT-COLON-UPARROW-SCOPE:TEST-FOR-REMAINING-ARGUMENTS is desirable
only because it maintains the equivalence of ~:#â?? and ~:â?? and because
some implementations have been produced that take this approach.


Current practice:

Implementations using FORMAT-COLON-UPARROW-SCOPE:TEST-FOR-REMAINING-SUBLISTS
include Symbolics Common Lisp.

Implementations using FORMAT-COLON-UPARROW-SCOPE:TEST-FOR-REMAINING-ARGUMENTS
include Kyoto Common Lisp, Allegro Common Lisp, GCLISP, and VAXLISP.


Cost to Implementors:

One or the other batch of implementors will have to make a one-line change.


Cost to Users:

It is unlikely that much user code depends on the behavior
FORMAT-COLON-UPARROW-SCOPE:TEST-FOR-REMAINING-ARGUMENTS, but it is
possible.  The author of this writeup (Steele) judges it somewhat more
likely that user code might depend on the behavior
FORMAT-COLON-UPARROW-SCOPE:TEST-FOR-REMAINING-SUBLISTS.


Cost of non-adoption:

Users would have to be warned not to use ~:â?? in code that is meant to be
portable.


Benefits:

Elimination of yet one more ambiguity.

FORMAT-COLON-UPARROW-SCOPE:TEST-FOR-REMAINING-SUBLISTS allows greater
semantic power (there are more things one can test).

FORMAT-COLON-UPARROW-SCOPE:TEST-FOR-REMAINING-ARGUMENTS maintains an
elegant but useless symmetry.


Esthetics:

Absolutely none.  We're talking about FORMAT here.


Discussion:

Nick Gall favors FORMAT-COLON-UPARROW-SCOPE:TEST-FOR-REMAINING-SUBLISTS.

Kevin Layer, Rich Robbins, and Robert Poor have spoken in favor of
FORMAT-COLON-UPARROW-SCOPE:TEST-FOR-REMAINING-ARGUMENTS.

Guy Steele strongly prefers the interpretation
FORMAT-COLON-UPARROW-SCOPE:TEST-FOR-REMAINING-SUBLISTS.

Historical note: Steele first implemented this "feature", in Zetalisp, and
so the code in Symbolics Common Lisp is likely a direct descendant of the
original code.  This might cause some to give weight to Steele's opinion.
There are two arguments against such credence.  First, there is no reason
why the original code should be regarded as part of the specification of
Common Lisp any more than any other implementation; plainly, Steele botched
the specification when he wrote the book.  Second, a professor of
literature (I believe) once told Isaac Asimov concerning a short story of
his (I quote from memory): "Tell me, Dr. Asimov, just because you wrote the
story, what makes you think you know what it means?"