beetlebug▾
/

tcl::mathop string

The commands of the operators that compare values as strings.

tcl::mathop::eq ?STRING ...?
tcl::mathop::ne STRING STRING
tcl::mathop::lt ?STRING ...?
tcl::mathop::gt ?STRING ...?
tcl::mathop::le ?STRING ...?
tcl::mathop::ge ?STRING ...?

Description

Each command compares its arguments as strings, also when they are numbers: eq 1 1.0 is 0, and lt 10 9 is 1. The order is the order of the code points of the characters, so an uppercase ASCII letter comes before a lowercase one.

eq, lt, gt, le, and ge accept any count of arguments and give 1 when each pair of neighbor arguments is in the relation. With no argument or one argument they give 1. ne needs exactly two arguments.

lt, gt, le, and ge are in Tcl 9.1 only. In expr they have the precedence of <.

Arguments

ArgumentTypeDefaultDescription
STRINGstringrequiredA value to compare as a string.

Returns

1 or 0.

Examples

% tcl::mathop::eq a a a
1

% tcl::mathop::eq 1 1.0
0

% tcl::mathop::ne 1 1.0
1

# Tcl 9.1 only
% tcl::mathop::lt 10 9
1

# Tcl 9.1 only
% tcl::mathop::lt B a
1

# Tcl 9.1 only
% tcl::mathop::le a a b
1

# Tcl 9.1 only
% tcl::mathop::ge 2 10
1

# Tcl 9.1 only
% expr {"b" gt "a"}
1

Errors

% tcl::mathop::ne a b c
wrong # args: should be "tcl::mathop::ne value value"
-errorcode TCL WRONGARGS

# Tcl 8.6 only
# Tcl 8.6 has no lt.
% tcl::mathop::lt a b
invalid command name "tcl::mathop::lt"
-errorcode TCL LOOKUP COMMAND tcl::mathop::lt

Tcl 8.6 and Tcl 9.1

Facts

Capability
None.
Tcl release
Tcl 9.1 and 8.6.
Since
ztcl 1.0.0-beta.1

See also