unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* conditional code segments
@ 2018-06-01 23:37 Matt Wette
  2018-06-02  1:11 ` Alex Vong
  2018-06-02  1:56 ` Mark H Weaver
  0 siblings, 2 replies; 4+ messages in thread
From: Matt Wette @ 2018-06-01 23:37 UTC (permalink / raw)
  To: guile-user

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

I can use (if #f (begin ....)) but it's not pretty and indents 4 spaces (or an ugly 1 space).

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

My current attempt is to add this:

   (define-syntax-rule (if-true form ...) (begin form ...))
   (define-syntax-rule (if-false form ...) (begin))

   (if-false
    (define x ...)
    ...
    )

   (if-true
    (define x ...)
    ...
    )

Any other solutions / suggestions?





^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: conditional code segments
  2018-06-01 23:37 conditional code segments Matt Wette
@ 2018-06-02  1:11 ` Alex Vong
  2018-06-02  1:56 ` Mark H Weaver
  1 sibling, 0 replies; 4+ messages in thread
From: Alex Vong @ 2018-06-02  1:11 UTC (permalink / raw)
  To: Matt Wette; +Cc: guile-user

[-- Attachment #1: Type: text/plain, Size: 1169 bytes --]

Matt Wette <matt.wette@gmail.com> 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 #|...|#.
>
> I can use (if #f (begin ....)) but it's not pretty and indents 4 spaces (or an ugly 1 space).
>
> 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))
>
> My current attempt is to add this:
>
>   (define-syntax-rule (if-true form ...) (begin form ...))
>   (define-syntax-rule (if-false form ...) (begin))
>
>   (if-false
>    (define x ...)
>    ...
>    )
>
>   (if-true
>    (define x ...)
>    ...
>    )
>
> Any other solutions / suggestions?

Maybe you can try to use #; to comment out s-exp? I prefer this way
because it feels very lispy to me.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 227 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: conditional code segments
  2018-06-01 23:37 conditional code segments Matt Wette
  2018-06-02  1:11 ` Alex Vong
@ 2018-06-02  1:56 ` Mark H Weaver
  2018-06-02  2:34   ` Matt Wette
  1 sibling, 1 reply; 4+ messages in thread
From: Mark H Weaver @ 2018-06-02  1:56 UTC (permalink / raw)
  To: Matt Wette; +Cc: guile-user

Hi Matt,

Matt Wette <matt.wette@gmail.com> 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



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: conditional code segments
  2018-06-02  1:56 ` Mark H Weaver
@ 2018-06-02  2:34   ` Matt Wette
  0 siblings, 0 replies; 4+ messages in thread
From: Matt Wette @ 2018-06-02  2:34 UTC (permalink / raw)
  To: guile-user

On 06/01/2018 06:56 PM, Mark H Weaver wrote:

> Hi Matt,
>
> Matt Wette <matt.wette@gmail.com> 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 use #; a lot.   So for large number of forms then #;(begin ...) should work.
And I didn't know white space can separate the #; from the Scheme form.  Cool.

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

Thanks much.




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-06-02  2:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-06-01 23:37 conditional code segments Matt Wette
2018-06-02  1:11 ` Alex Vong
2018-06-02  1:56 ` Mark H Weaver
2018-06-02  2:34   ` Matt Wette

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).