modern Tcl and correct quoting
Ryan Schmidt
ryandesign at macports.org
Wed Jun 12 14:57:38 PDT 2013
On Jun 12, 2013, at 16:46, Gustaf Neumann wrote:
> In a related but different area, the expression "?:" can be dangerous:
>
> set x nan
> expr {1 ? $x : 0}
I've long wondered why we don't use the ternary operator in MacPorts. For the longest time I thought Tcl didn't have one, but it does. The above expr produces the error "domain error: argument not in valid range" so I guess that's why you say it's dangerous and that might be a good reason to continue to avoid its use. However, I don't know why we would ever have a "nan" in MacPorts.
> These are a good reason to stay away from numeric expressions
> unless necessary.
I would guess that most programmers who wrote "==" in Tcl didn't realize it was a numeric comparison operator. It certainly wasn't clear to me, since it works correctly on most strings. That kind of thing trips me up in bash scripting as well. In addition to base, most Portfiles get this wrong too. It's even all over our recommended code snippets in the PortfileRecipes wiki page.
More information about the macports-dev
mailing list