GNU bug report logs - #50614
[PATCH core-updates] build: utils: Add ‘optional’ macro.

Previous Next

Package: guix-patches;

Reported by: Xinglu Chen <public <at> yoctocell.xyz>

Date: Thu, 16 Sep 2021 07:12:02 UTC

Severity: normal

Tags: patch

Full log


Message #11 received at 50614 <at> debbugs.gnu.org (full text, mbox):

From: Sarah Morgensen <iskarian <at> mgsn.dev>
To: Xinglu Chen <public <at> yoctocell.xyz>
Cc: 50614 <at> debbugs.gnu.org
Subject: Re: [bug#50614] [PATCH core-updates] build: utils: Add
 ‘optional’ macro.
Date: Thu, 16 Sep 2021 17:37:24 -0700
Hi,

Xinglu Chen <public <at> yoctocell.xyz> writes:

> * guix/build/utils.scm (optional): New syntax
> * tests/build-utils.scm ("optional: expr1 is non-#f", optional: expr1 is #f"):
>   Test it.
> * guix.texi (Build Utilities): Document it.
> ---
> A common idiom I have seen is
>
>   (if EXPR1
>       EXPR2
>       '())
>
> with the ‘optional’ macro, one can just write
>
>   (optional EXPR1
>             EXPR2)
>
> I am not sure if ‘optional’ is the best name (it was inspired by
> ‘lib.optional’ in Nixpkgs), feedback welcome!

I like the idea!  But perhaps if we're getting rid of boilerplate, we
should go all the way and make it so that instead of

  (if EXPR1
      `(EXPR2 EXPR3)
      '())

we can write

  (optional EXPR1 EXPR2 EXPR3)

What do you think?

Also, maybe 'list-when' for the name?

> +@deffn {Scheme Syntax} optional @var{test} @var{consequent}
> +Like @code{when} (@pxref{Conditionals,,, guile, GNU Guile Reference
> +Manual}), but if @var{test} evaluates to false, return the empty list.
> +This is replaces the following idiom:
        ^ no "is"

> +@end deffn
> +
> +@lisp
> +(if @var{test}
> +    @var{consequent}
> +    '())
> +@end lisp
> +
> +with this:
> +
> +@lisp
> +(optional @var{test}
> +          @var{consequent})
> +@end lisp          
> +
> +It can be useful when certain targets require an additional configure
                                                 ^ no "an"

> +flags, e.g.,
> +
> +@lisp
> +(arguments
> + `(#:configure-flags (list "--localstatedir=/var"
> +                           "--sysconfdir=/etc"
> +                           ,@@(optional (hurd-target?) '("--with-courage"))))
                               ^ extra "@"?

--
Sarah




This bug report was last modified 3 years and 267 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.