TIP 773: Raw Commands in Expressions (provisional)

Login
Author:         Florent Merlet <[email protected]>
State:          Draft
Type:           Project
Vote:           Pending
Created:        29-Oct-2026
Tcl-Version:    9.2
Keywords:       expr, command
Post-History:

Abstract

In an expression, some commands may be written without brackets:

expr {llength $L + 1}              ;# [llength $L] + 1
proc dot {U V} {( s = 0; foreach u $U v $V {( s = $s + $u*$v )}; $s )}

It is the sixth part of TIP 759. This part is provisional: the list of command names is fixed in the parser for now, and is to be replaced by a register of the commands allowed without brackets. It is published so that the register can be designed and tested on a working base.

Specification (current implementation)

  1. A raw command is a command whose name is one of concat dict for foreach global if incr lappend lassign lindex llength lmap lrange lset namespace return string switch upvar variable while, followed by a space, where an operand is expected.

  2. It ends at a ;, at an operator or a close parenthesis that begins a word, or at the end of the expression. The terminator is then parsed as part of the expression. An operator inside a word does not end it: lindex $L end-1 is one command. Newlines separate the commands of a raw script.

  3. Its result is the value of the operand.

  4. C API. A new token type TCL_TOKEN_CMD_IN_EXPR (512), the text of the command, no components. Tcl_ParseCommand accepts a new value of nested, TCL_CMD_NESTED_IN_EXPR (internal), and the character table of the parser gets a TYPE_OP class for the operator characters.

Open questions, for the register

Implementation

Patch 0006-TIP-759-6-7-raw-commands-in-expressions-provisional.patch:

This document has been placed in the public domain.