TIP: | 282 |

Title: | Enhanced Expression Syntax |

Version: | $Revision: 1.4 $ |

Authors: |
Will Duquette <William dot H dot Duquette at jpl dot nasa dot gov> Don Porter <dgp at users dot sourceforge dot net> |

State: | Draft |

Type: | Project |

Tcl-Version: | 8.7 |

Vote: | Pending |

Created: | Friday, 13 October 2006 |

Keywords: | expr, operator, assignment |

This TIP extends the syntax of the **expr** command to allow a sequence of mathematical computations to be expressed clearly and concisely.

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.

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.

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.

See [1]

This document has been placed in the public domain.

[Index] [History] [HTML Format] [Source Format] [LaTeX Format] [Text Format] [XML Format] [*roff Format *(experimental)*] [RTF Format *(experimental)*]