(06-03-2023, 10:32 PM)mnrvovrfc Wrote: I get by like this:
Code: (Select All)dim i as _integer64, f as _float, x as _integer64, y as _float, s as string
i = iff(x > 5, x - 1, x * 2)
f = ifff(y < 0, 1, sqr(y))
s = iffs$(x = 0, "true", "false")
end
function iff&& (cond%%, truevalu&&, falsvalu&&)
if cond%% then
iff&& = truevalu&&
exit function
end if
iff&& = falsvalu&&
end function
function ifff## (cond%%, truevalu##, falsvalu##)
if cond%% then
ifff## = truevalu##
exit function
end if
ifff## = falsvalu##
end function
function iffs$ (cond%%, truevalu as string, falsvalu as string)
if cond%% then
iffs$ = truevalu
exit function
end if
iffs$ = falsvalu
end function
It requires three functions, one for integers, another for floating point and another for strings, that's the main drawback. But be glad BASIC doesn't have a "boolean" type that would have prevented the straight-out use of a condition which is evaluated and passed along as integer value.
BAM programs being interpreted by javascript (i.e. wwwbasic.js, significantly modified), it took me all of 10 minutes to just go ahead and setup an IFF function.
Although not very BASIC-like, (javascript not being strongly typed) the IFF function works as-is for both strings and whatever numbers (so I'm kind of appreciating the no fuss no muss compactness).
Your workaround is quite lovely, though. That would make for an excellent include library.