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

Re: nested comments

This page is part of the web mail archives of SRFI 62 from before July 7th, 2015. The new archives for SRFI 62 contain all messages, not just those from before July 7th, 2015.

On Tue, 4 Jan 2005, David Van Horn wrote:

> What does the following evaluate to?
>    (list 'x #;#;'y 'z)

MzScheme & Chez, as Robby Findler demonstrated, both give the list (X).
This is correct.  (SISC & Chicken do, too.)  The reason is that #;
ignores the single next following S-expression and allows the reader to
continue on after that.  In the string "#;'y 'z", the #; comments out
the 'Y part, leaving the 'Z part.  Since a #; precedes that string in
your example, the 'Z part is ignored, too, so the whole thing is read
as (LIST (QUOTE X)), which evaluates to the list (X).

This is an excellent & possibly initially confusing example (though the
explanation is simple & straightforward), so I'll add it to the SRFI
document.  I'll also add another example of nested comments, too:

  (list 'a #;(list 'b #;'c 'd) 'e)    ==>  (LIST (QUOTE A) (QUOTE E))

The inner #; comments out the following 'C, but the list structure that
lies a layer above it is still read as a complete S-expression -- in
particular, (LIST (QUOTE B) (QUOTE D)) --.  Then the outer #; comments
that out, leaving only (LIST (QUOTE A) (QUOTE E)), which evaluates to
the list (A E).