Email list hosting service & mailing list manager

nested comments David Van Horn (04 Jan 2005 22:06 UTC)
Re: nested comments Robby Findler (04 Jan 2005 22:17 UTC)
Re: nested comments Taylor Campbell (04 Jan 2005 23:10 UTC)
Re: nested comments Per Bothner (05 Jan 2005 00:18 UTC)
Re: nested comments Taylor Campbell (05 Jan 2005 00:45 UTC)

Re: nested comments Taylor Campbell 04 Jan 2005 23:52 UTC

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).