TIP 637: Make [glob] always -nocomplain

Author:         Don Porter <[email protected]>
State:          Final
Type:           Project
Vote:           Done
Created:        17-Sep-2022
Tcl-Version:    9.0
Tcl-Branch:	novem
    Vote-Summary:   Accepted 6/0/0
    Votes-For:      DP, JN, SL, FV, KK, KW
    Votes-Against:  none
    Votes-Present:  none


This TIP proposes revising the behavior of [glob] to return an empty list without error when no matches are found.


When [glob] finds zero matching files, it raises an error.

% glob noSuchFile
no files matched glob pattern "noSuchFile"

This is unfortunate because when using [glob], finding zero matches is no more an indication of error than finding one or finding 42. Using [catch] to deal with this misfeature was an annoying burden, and in the days before [try] and a strong deployment of --errorcode values, it was burdensome to distinguish the caught circumstance of zero matches from true error conditions like a file system failure, or a syntax error in argument substitution.

The -nocomplain option was added to [glob] long ago. It was in place at least by Tcl 8.0. When present, this option disables the treatment of any empty result as an error.

% glob -nocomplain noSuchFile

With this option, the [glob] command could be used more effectively and robustly.

In hindsight, [glob -nocomplain] is the better primitive, and should have been the original behavior of the command. For a new major release, [glob] can become what it should have been in the first place.


Revise [glob] so that it does not raise an error when no matches are found.

Keep accepting -nocomplain as an option, but it has no effect.


The only compatibility issue is with any programmer who wants [glob] to raise an error when no matches are found. It is believed this will be a very uncommon desire.

Such a programmer can create a proc to post-process an empty list returned by [glob] into an error. Tcl namespaces then allow the programmer to favor his proc over the built-in command, or even to replace the built-in with it when circumstances make that sensible.

Reference Implementation

This change has long been implemented in the novem branch, and should not be difficult to extract and apply.


This document has been placed in the public domain.