TIP 712: Add "positive" options to the subst command

Login
Author:         Reinhard Max <[email protected]>
State:          Draft
Type:           Project
Created:        30-Jan-2025
Tcl-Version:    9.0.1
Tcl-Branch:     tip-712
Keywords:       subst

Abstract

This TIP proposes to add "positive" options to the subst command for specifying the kinds of substitutions that should be performed rather than the ones that should be suppressed.

Background

It has always bothered me that when I don't want all kinds of substitutions to happen I have to tell subst the kinds I don't want rather than being able to tell it the ones I do want.

Rationale

Being able to specify a positive list of wanted substitutions will make the code more readable as they are slightly shorter and don't require the reader to subtract the list of given options from the list of possible substitutions.

Specification

Add new options named -backslashes, -commands, and -variables to the subst command that are counterparts to the existing options -nobackslashes, -nocommands, and -novariables. If at least one of them is present the default of all three kinds of substitutions being active would change to only the positively specified ones being active.

It is an error to mix positive and negative switches.

Rejected alternatives

I was considering to allow mixed-sign switches as long as they don't create ambiguity, but then decided to leave that out for now unless the community comes up with good reasons for having it.

Compatibility

Existing scripts don't need to be touched, because no option gets removed and the default does not change. Scripts using the new options will not be backwards compatible with Tcl 9.0.0 and older.

Reference Implementation

A reference impementation can be found in Tcl branch tip-712.

Copyright

This document has been placed in the public domain.