[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug#50614] [PATCH core-updates] build: utils: Add ‘optional’ macro.
From: |
Sarah Morgensen |
Subject: |
[bug#50614] [PATCH core-updates] build: utils: Add ‘optional’ macro. |
Date: |
Thu, 16 Sep 2021 17:37:24 -0700 |
Hi,
Xinglu Chen <public@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