Updated 2012-07-11 11:04:59 by RLE

Problem: [package require] is limited in what requirements you can express.

I need Tcl of at least version 7.5

Best current expression:
    if {[catch {package require Tcl 8}]} {
        package require Tcl 7.5

...and that will need more branches to support Tcl 9.

I need foo 1.2 or better, except for foo 1.3.4, which I know has a bug I can't work around, but I know it got fixed in 1.3.5, and it's still working with the current release 2.3.1

Probably the best solution currently is to temporarily remove any [package ifneeded foo 1.3.4] registration before calling [package require]. If the bug covers many releases, though, that can be tedious.

So, how about an extension of the [package require] syntax to:

package require $package ?$range ...?

A range would have the form: $minVersion?-$maxVersion?

The interpretation is that version $minVersion is acceptable, and all versions greater than $minVersion and less than $maxVersion are acceptable.

As a special case, if $minVersion and $maxVersion are the same, then only exactly that version is acceptable. That is,
    package require bar 1.3.2-1.3.2

is equivalent to
    package require -exact bar 1.3.2

(but gets rid of the nasty switch!)

For compatibility, if only a single $minVersion is supplied, then the default $maxVersion value is the next higher major version. For example,
    package require foo 1.2

is equivalent to
    package require foo 1.2-2

If the - appears, but no $maxVersion, then there is no upper limit.

For the examples above:
    package require Tcl 7.5-9

and when Tcl 9 is released, and we see that our program still works:
    package require Tcl 7.5-10

Or, if we want to make the users our testers for compatibility with future Tcl:
    package require Tcl 7.5-

The second example:
    package require foo 1.2-1.3.4 1.3.5-3