Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!softrue!kearns From: kearns@softrue.UUCP (Steven Kearns) Newsgroups: comp.lang.c++ Subject: simplifying C++ Message-ID: <5.UUL1.3#8618@softrue.UUCP> Date: 20 Feb 91 05:37:04 GMT Organization: Software Truth Lines: 37 Here is another in the continuing series: "Simplifying C++". Expression languages are languages where each statement returns a value. Lets make C++ an expression language as follows: Expression Statements, like "a = 5;", return the value of the expression. "if (e1) s1; else s2;" returns the value of s1 if e1 true, otherwise it returns the value of s2. If s1 and s2 return values of different types, the "if" returns a void. "{s1; s2; s3;} returns the value of the last statement in the compound statement. All other statements, including an if statement without an else, return void. The advantage of this is manyfold: first, we get to eliminate the comma operator, which is used to evaluate multiple expressions as in (e1, e2, e3). Instead, you can write {e1; e2; e3;}. Also, we can eliminate the ugly (B ? e1 : e2) syntax, writing (if (B) e1; else e2;) instead. Also, you can do things impossible before, for example declaring variables inside expressions: if {int i = f(a, b); i >=3 && i <= 33;} cout << "hi there"; We probably want to disallow "gotos" and "returns" inside a compound statement used as an expression. -steve ******************************************************** * Steven Kearns ....uunet!softrue!kearns * * Software Truth softrue!kearns@uunet.uu.net * ********************************************************