Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!decwrl!pa.dec.com!decprl!decprl!weikart From: weikart@prl.dec.com (Chris Weikart) Newsgroups: comp.lang.c++ Subject: Re: simplifying C++ Message-ID: <1991Mar5.195042.6263@prl.dec.com> Date: 5 Mar 91 19:50:42 GMT References: <5.UUL1.3#8618@softrue.UUCP> Sender: news@prl.dec.com (USENET News System) Reply-To: weikart@prl.dec.com (Chris Weikart) Organization: Digital Equipment Corporation - Paris Research Laboratory Lines: 51 In article <5.UUL1.3#8618@softrue.UUCP>, kearns@softrue.UUCP (Steven Kearns) writes: |> |> 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 * |> ******************************************************** The comma operator must have been invented for "for" loops; it's usefulness in macros was, in my opinion, unforeseen and fortuitous. "For" loops require a separator with lower (or higher? I can never get this straight) priority than the ";" in order to allow multiple expressions for each of the three parts. ------------------------------------------------------------------------------- Chris Weikart .............. DEC Paris Research Lab (PRL)