expr should be deprecated

I hope the expr command gets deprecated

Since TIP 174: Math Operators as Commands I would have hoped that all future improvement would go into Math Commands

But I see several pending tip suggesting improvements to the expr command

I hope that those tips get abandoned or withdrawn Adding mini languages to Tcl is in my opinion very bad language design and adds complexity

I understand that expr is part of Tcl's history and heritage, but I think as Tcl seem moving toward version 9 and hopefully towards a slight revival, I think its also time to just declare commitment to Tcl's command syntax it is in my opinion cleaner and less confusing and promotes homoiconicity better (for my poor understanding of what homoiconicity means)


KJN 2023-04-16 17:45:00

When learning Tcl it was surprising to find that the syntax of expr did not conform to the usual Tcl rules - for example, it is necessary to quote a string literal, but not a string that is the value of a variable.

It might be possible to "improve" expr syntax - for example, now that we have the string operators "eq" and "ne", is it useful to allow "==" and "!=" to perform string comparisons when their arguments are not numbers? Further "improvements" are possible if spaces are required between the elements of an expression, but at the cost of breaking old code and consistency with other languages.

In any case, we need expr if we want to do numerical operations with infix notation. I much prefer

    expr {sin($theta * $pi / 180.)**2}

to the Tcl-compliant form

    ** [sin [/ [* $theta $pi] 180.]] 2

stevel 2023-03-01 08:14:18

I don't see expr ever being deprecated, but do think a discussion of ways to better handle expressions would be helpful. As you have noted, there are already proposals on the table.

At present there is a focus on getting 9.0 out the door but there's no reason why you couldn't revive the discussion with a view to the feature being in Tcl 9.1. A good place to start would be Math Operators as Commands.


SYStems 2023-03-01 12:42:19 PM

Tcl is a nice glue language, the ultimate glue language in my opinion. I think the command line interface is the best option for glue languages I also like a lot John Ousterhout Ousterhout's Dichotomy.

So Tcl hosting secondary language is not necessarily a horrible idea. regexp can be considered as a mini or secondary language inside Tcl.

But I can't think of math operators as mini language, so I think either expr should be deprecate or be repositioned as a gateway (interface) to a more complete math system (another language/interpreter that does math better)

This way Tcl can delegate Math / Regexp to other interpreters that have better implementations for those features.

PYK 2023-03-03: Math operators as individual procedures do not expose the full power of expr, which provides parenthesis for grouping and precedence, and also provides the logical operators, which are lazy in the sense that only the true branches are evaluated. expr is one of the standard languages Tcl provides. It's useful and it is here to stay. expr could one day provide and assignment operator and even provide ";" as an expression delimiter. Maybe it will. In the meantime, there's nothing stopping anyone from implementing another command that provides access to another math system. That's what Tcl is for.