Only Syntax

Journal of my investigation into the development of a new programming language

Sunday, April 06, 2003

 

Conditionals: Question/Answer/Action



Here is what I want to use for conditionals:


[is] a > 5?
if so: print "big"
if not: print "small"

[is] a > 5?
yes:
print "big"
subtract 3 from a
no:
print "small"
add 2 to a

[what is] a?
it > 5: print "big"
it > 3: print "medium"
otherwise: print "small"

[what is] a?
> 5:
print "big"
subtract 3 from a
> 3:
print "medium"
else:
print "small"
add 2 to a


It treats IF and CASE consistently.

It splits out the two roles of the conventional IF clause - generally, IF represents both question and (answer = true), while ELSE represents only (answer = false). Which leads to problematic issues like ELSE IF.

The only objection I have to this is that simple multiline IF's require double-indentation. This implies that the code is more complex than it really is. I want apparent code complexity to correspond closely to actual code complexity, and I want to reduce indentation levels generally, with things like implicit loops and trailing IF and UNLESS clauses. But at the moment, at least, I'm willing to accept the extra indentation for the sake of consistency.

A few little notes: "if" and "it" can be left off the answer clauses; "if so" is synonymous with "if it is" and "yes"; "if not" is synonymous with "no" (in the answer clause context); questions load the special "it" variable.

Comments: Post a Comment

<< Home

Archives

03/30/2003 - 04/06/2003   04/06/2003 - 04/13/2003   10/12/2003 - 10/19/2003   01/09/2005 - 01/16/2005   01/16/2005 - 01/23/2005  

This page is powered by Blogger. Isn't yours?