2011-12-31

else-if statement's syntax

12.10: adda/cstr/else-if:

. here is the if-else syntax:
t?
 ( c1: s1
 , c2: s2
 , else: s3
 ) .
if I add an elsif to the structure, how does that fit in ?;
actually, with the use of (?) instead of (if)
there's maximum brevity without using a
contraction of  [else if] .
. using that case-style syntax, it'd look like this:
t1 ? ( s1
, else: t2 ? (s3
, else: t4 ? (s5
, else: s6 ))).
. using truth-style syntax, it looks normal:
t1 ? s1
else t2 ? s3
else t4 ? s5
else s6 .
-- neat, but since (if) doesn't have a terminator
(like ada's endif,
any nested if-else's have to be parenthesized
as do any statement sequences:
t1 ?
  s1
else t2 ?
  (t1 ? s1 else t2 ? s3 else t4 ? s5 else s6 )
else t4 ?
  (s1; s2)
else
  s6 .

[if vs ?]:
. if you'd rather use if's, then (t?) is generally
replaceable with (if t:); ie,
the (:) is acting as a terminator like the (?) does .
mis:
. at first I was seeing it as a case stmt
with more than one case possible
the thing need to be ordered
reminds of using (;) instead of (,)
as is structuring arrays into matrices .
even if I could make the matrix pattern fit,
I'm not sure a tired or new programmer could
keep a working knowledge of it .

sci:
. notice that since both of (if)'s args are required,
then you could also separate them with a space
like lisp does; in that case,
you'd be detecting the condition where
the next token in the 2nd arg has to be an infix
but instead you found a non-infix;
however, that wouldn't work in my current syntax,
because infix's can also serve as prefix's;
so the (if)'s arg's  do need a separator,
and a natural for that situation is the colon .
then again:
. you could also tell that the (if)'s 2nd arg began
because the next infix you were expecting
would have to be a truth-operator, ie:
{ or, and; nor, nand,
<=>, -- x is/not equivalent to y ( is also called xor, exclusive-or),
=>, =/> -- x does/not imply y,
<=, }
another prequisite:
. the other problem with not using the colon,
is that you can no longer have overloading;
you'd have to reserve the logical operators;
and while it does add unnecessarily to bureaucracy,
it would aid considerably to readability .
nevertheless:
. speaking of readability, use of the separator would
make it easy for humans to quickly parse;
and while adda should let writers skip the separator,
it should provide the readers the option of viewing it;
ie, it would be part of the
full vs minimized punctuation theme .
the deal breaker:
. finally, an insurmountable problem is one of
users adding more binary logic operators,
or similar functions of the form:
(truth, other-type)->truth .
. they should be able to do that,
so, you'd also have to make a general rule about
no overloading of such,
and that would be too much bureacracy
for the sake of merely simplifying (if)'s .

list of truth-operators:
. here is a table of possible combinations on 2 variables, x,y;
and the operations that can detect those combinations .
(~x&~y, ~x&y, x&~y, x&y) -- operation:
------------------------------------------
0000 -- false (regardless of inputs)
0001 -- x&y -- x and y
0010 --  x&~y -- not( ~x or y) -- x =/> y
0011 --  x (regardless of y)
0100 -- ~x&y -- not (x <= y)
0101 -- y (regardless of x)
0110 -- ~x&y or x&~y -- xor --
0111 -- x or y
1000 -- ~x&~y -- not(x or y) -- nor
1001 -- ~x&~y or x&y -- <=>
1010 -- ~y (regardless of x)
1011 -- not (~x&y) -- x or ~y -- x <= y
1100 -- ~x (regardless of y)
1101 -- not(x&~y) -- ~x or y -- x => y
1110 -- not(x&y) -- ~x or ~y -- nand,
1111 -- true (regardless of inputs)

the same rearranged by category:

non-binary logic:
truth values:
0000 -- false (regardless of inputs)
1111 -- true (regardless of inputs)
variable values:
0011 --  x (regardless of y)
1100 -- ~x (regardless of y)
0101 -- y (regardless of x)
1010 -- ~y (regardless of x)

classic binary logic:
0001 -- x and y
0111 -- x or y
1101 -- not(x&~y) -- ~x or y -- x => y
0010 --  x&~y -- not( ~x or y) -- x =/> y
1001 -- ~x&~y or x&y -- <=>
0110 -- ~x&y or x&~y -- xor --
modern binary logic:
1110 -- not(x&y) -- ~x or ~y -- nand,
1000 -- ~x&~y -- not(x or y) -- nor
english binary logic:
1011 -- not (~x&y) -- x or ~y -- x <= y -- implied by
0100 -- ~x&y -- not (x <= y) -- not implied by