TIP #282: ENHANCED EXPRESSION SYNTAX ====================================== Version: $Revision: 1.4 $ Author: Will Duquette Don Porter State: Draft Type: Project Tcl-Version: 8.7 Vote: Pending Created: Friday, 13 October 2006 URL: https://tip.tcl-lang.org282.html Post-History: ------------------------------------------------------------------------- ABSTRACT ========== This TIP extends the syntax of the *expr* command to allow a sequence of mathematical computations to be expressed clearly and concisely. RATIONALE =========== The ugliness of mathematical code written in Tcl is a perennial source of complaint. Consider the following computation: set x [expr {5*$y + 6*$z}] set w [expr {$x**2 + $y**2}] set v [expr {$w**2 + $y**2}] The [*expr {...}*] constructs make the code considerably harder to read. But suppose *expr* syntax included an assignment operator: expr {x = 5*$y + 6*$z} expr {w = $x**2 + $y**2} expr {v = $w**2 + $y**2} Next, suppose that an *expr* expression could include subexpressions, delimited by a ";" character: expr { x = 5*$y + 6*$z; w = $x**2 + $y**2; v = $w**2 + $y**2 } The sequence of computations is now much clearer. SPECIFICATION =============== ASSIGNMENT OPERATOR --------------------- The *expr* syntax should be extended with an assignment operator which has C-like semantics, i.e., the result of an assignment is the assigned value. This operator shall be written as "*=*". The term on the left side of the operator shall be a variable name, and the term on the right side of the operator shall be any expression. The result of the overall assignment expression shall be the result of the subexpression on the right hand side of the operator. EXPRESSION SEPARATOR OPERATOR ------------------------------- An *expr* expression can be separated into subexpressions by the semicolon ("*;*") character, which will have the same semantics as the "," operator in C. Thus, the return value of a call to *expr* is the value of the final subexpression, and the both sides of the expression shall be expressions. REFERENCE IMPLEMENTATION ========================== See [] COPYRIGHT =========== This document has been placed in the public domain. ------------------------------------------------------------------------- TIP AutoGenerator - written by Donal K. Fellows