guile-user
[Top][All Lists]
Advanced

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

Re: conditional code segments


From: Mark H Weaver
Subject: Re: conditional code segments
Date: Fri, 01 Jun 2018 21:56:36 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)

Hi Matt,

Matt Wette <address@hidden> writes:

> In C I can use `#ifdef' .. `#endif' to "comment out" code segments.
>
> In Scheme, one can use `#|' and '|#' which is OK but requires dealing with 
> both ends of the
> segment to switch on / off.  And emacs (v 24.5) scheme mode does not always 
> fontify the buffer
> correctly with #|...|#.

There's another kind of comment in standard Scheme (both R6RS and R7RS)
that's supported by Guile, but unfortunately it doesn't seem to be
documented in our manual.  Simply put the two characters "#;" before any
datum, and the entire datum will be skipped by the reader.  Whitespace
may appear between "#;" and the datum.  So, for example:

#;
(let ()
  ...)

will cause the entire 'let' form (which is a datum) to be skipped.
Emacs and paredit understand this syntax, and will act accordingly.

It works not only at top-level, but also nested arbitrarily deeply
within datums.  So, for example:

  scheme@(guile-user)> (let ()
                         (display "1\n")
                         (display "2\n")
                         #;
                         (display "3\n"))
  1
  2
  scheme@(guile-user)> 

and if you put that code in an Emacs buffer in Scheme mode, the
(display "3\n") will be colorized as a comment, but the final closing
parenthesis will have the default color.

> I tried using cond-expand but it does not work as expected:
>   scheme@(guile-user)> (cond-expand-provide (current-module) '(abc))
>   $1 = (abc)
>   scheme@(guile-user)> (cond-expand (abc #t))
>   While compiling expression:
>   Syntax error:
>   unknown file:2:0: cond-expand: unfulfilled cond-expand in form (cond-expand 
> (abc #t))

It didn't work because when a 'cond-expand' form is used in module FOO,
it looks for the features (e.g. 'abc') in all of the modules that are
imported by FOO, but not in FOO itself.

       Mark



reply via email to

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