| Store | Cart

Re: [TCLCORE] TIP #461: Separate Numeric and String Comparison Operators

From: Peter S <pete...@gmail.com>
Wed, 1 Feb 2017 19:48:33 +0100
Such an "operator validator" program could also come handy in case the
language semantics change, because then there's no need to go through
all occurrences of operators, rather it's enough to check the cases
where warnings are given.

Due to the simple syntax of Tcl, parsing command substitutions in
expressions is also not particularly difficult, even in case of nested
command substitutions, so commands that are expected to give numerical
results, could be considered 'safe' comparisons.

Examples:

    if {[llength <whatever>] == 2} ...
	
    if {[string length $somestr] > 10} ...
	
    if {[string compare $x $y] >= 0} ...
	
So, if the command is [llength], [string length], [string compare],
... or any built-in command that is always expected to give a
numerical results, then that could be considered a 'safe' operation by
the validator, no need to review these tests one-by-one.

These tests should already cover most of the typical use cases...

Programs could be written to translate all the numerical command
substitutions to be strictly numerical, and auto-translate the above
expressions to:

    if {+[llength <whatever>] == 2} ...
	
    if {+[string length $somestr] > 10} ...
	
    if {+[string compare $x $y] >= 0} ...

So in case the the operator semantics remain polymorph, such a program
could auto-convert expressions to {+[command args] > 1} format,
hinting to the compiler that it's a numerical operation, allowing
efficient compilation. As [llength] always gives numerical result
(unless there's a radical language change, in which case the unary +
would trigger an error), no need to test whether the result is
numeric.

However, an optimizing compiler could do this automatically, without
the + hint - if one argument is a command substitution where the
result is expected to be numeric, the operation can be automatically
assumed numeric. If no radical language change happened (which would
be known to the compiler), these operations can always be assumed to
be numeric.

So in fact the compiler could already know in lots of cases, whether
the result of some command substitution is numeric or not, and use
strictly numeric operation where it makes sense.

Best regards,
Peter

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Tcl-Core mailing list
Tcl-...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tcl-core

Recent Messages in this Thread
Donald Porter Jan 31, 2017 05:09 pm
Peter S Jan 31, 2017 09:45 pm
Brad Lanam Feb 01, 2017 12:04 am
Kevin Kenny Feb 01, 2017 01:09 am
Brad Lanam Feb 01, 2017 01:26 am
Dipl. Ing. Sergey G. Brester Feb 01, 2017 07:57 am
Peter S Feb 01, 2017 01:13 pm
Peter S Feb 01, 2017 01:23 pm
Colin McCormack Feb 01, 2017 02:33 pm
Peter da Silva Feb 01, 2017 04:16 pm
Peter S Feb 01, 2017 04:27 pm
Peter S Feb 01, 2017 04:41 pm
Peter S Feb 01, 2017 05:10 pm
Peter S Feb 01, 2017 05:48 pm
Dipl. Ing. Sergey G. Brester Feb 01, 2017 06:45 pm
Peter S Feb 01, 2017 06:48 pm
Peter S Feb 01, 2017 10:07 pm
Peter S Feb 01, 2017 10:30 pm
Brian Griffin Feb 01, 2017 10:48 pm
Dipl. Ing. Sergey G. Brester Feb 01, 2017 05:11 pm
Peter S Feb 01, 2017 04:13 pm
Martin Lemburg Feb 01, 2017 03:31 pm
Martin Lemburg Feb 01, 2017 12:20 pm
Dipl. Ing. Sergey G. Brester Feb 01, 2017 01:20 pm
avl Feb 01, 2017 12:01 am
Donald G Porter Feb 02, 2017 06:21 pm
Peter S Feb 01, 2017 10:59 pm
Dipl. Ing. Sergey G. Brester Feb 02, 2017 08:29 am
avl Jan 31, 2017 05:04 pm
Peter S Jan 31, 2017 05:13 pm
Messages in this thread