tech-userlevel archive

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

Re: Improvement for bmake: boolean values

On Wed, Mar 25, 2009 at 10:21:34AM -0400, der Mouse wrote:
 > > To solve these problems I propose to implement new function for
 > > bmake, say "yesno", treating 1 and [Yy][Ee][Ss] as logical true, and
 > > 0 and [Nn][Oo] as logical false.
 > In case anyone feels like paying attention to my reactions: I don't
 > like this design; it feels too special-cased.

Me either, and I really don't like the name. At a minimum it should be
named such that it's clear how the truth values are interpreted; maybe
something like "istrue".

 > I'd much prefer adding
 > some kind of function definition syntax so that bsd.$ can
 > define yesno() itself.  As a strawman,
 > .function yesno(s) ((s ==i "yes") || (s == "1") || \
 >      ((s !=i "no") && (s != "0") && error("invalid yesno() argument"))
 > (I don't know whether ==i / !=i exist at present, though I think those
 > spellings of them don't; I mean case-insensitive == / !=.)

The right way to do this (or at least, the way consistent with the
material already in make) is to add support for $1..$n and an argument
list syntax for variable expansions.

That is, something like ${VAR:> arg1, arg2, arg3} binds $1=arg1,
$2=arg2, $3=arg3 and then expands VAR.

Then you'd get something like this:

ISTRUE=($1 ==i "yes") || ($1 == "1") || \
       (($1 !=i "no") && ($1 != "0") && ${.ERROR:> "Invalid truth value"})

.if ${ISTRUE:> ${FOO}}

.ERROR would need to be a builtin.

The precise choice of punctuation would need some thought so it's both
acceptable-looking and consistent with things that already exist.

I've floated this idea before a couple of times but it's always seemed
like a jumbo-sized can of worms. On the plus side, it's not that big a
jump to implement.

To accompany this it might be helpful to have multiline variable
assignments so variable expansions can contain loops and conditionals,
something like this:

.begin ISTRUE
.if $1 == "yes" || $1 == "YES" || $1 == "1"
.return 1
.elif $1 == "no" || $1 == "NO" || $1 == "0"
.return 0
.error "Invalid truth value: $1"

This is not so trivial to do without reworking the internals of make;
but that rework should probably be done regardless.

(Then there's the question of whether adding functions means it's
really time to also add some typechecking... etc. etc.)

David A. Holland

Home | Main Index | Thread Index | Old Index