Grupos de Google ya no admite publicaciones ni suscripciones nuevas de Usenet. El contenido anterior sigue visible.

invalid bareword in expression

243 vistas
Ir al primer mensaje no leído

heinrichmartin

no leída,
4 may 2018, 4:25:02 a.m.4/5/18
para
Hi,
out of curiosity: is there a reason for not accepting barewords as strings in expressions (expr/if).

background:
I know of [apply] and [list] to dynamically create commands, but in my particular use case I use the following pattern to inject a constant:

proc dynproc args [format {
# dynamically created proc body
...
if {%s eq ...} ... ;# does not always produce correct syntax
if {[::tcl::mathop::eq %s ...]} ... ;# 10% slower
...
} [list $const]]

Using (the string representation of a) [list] guaranties that the body has correct syntax in commands, but not in expressions. That's why I wonder whether there is a specific reason for this.

Regards
Martin

Arjen Markus

no leída,
4 may 2018, 4:53:31 a.m.4/5/18
para
I am not sure if there is a specific reason, but it is part of the general improvement of the [expr] command and related aspects of Tcl - see the various TIPs.

But what about: if {{%s} eq ...}

If you use the extra braces, the substituted string is acceptable and not a bare word. Unless you want to substitute %s by $variable ...

Regards,

Arjen

heinrichmartin

no leída,
4 may 2018, 5:14:11 a.m.4/5/18
para
On Friday, May 4, 2018 at 10:53:31 AM UTC+2, Arjen Markus wrote:
> But what about: if {{%s} eq ...}

I was thinking so, too, but it is not a general solution. This would work only if the canonical string representation of a list always uses backslash escapes.

A simple counterexample is [format {if {{%s} eq ...} ...} [list " "]]. Same for "%s"; and building the full expression with list is not a solution either.

briang

no leída,
4 may 2018, 3:49:56 p.m.4/5/18
para
The reason is that the [expr] language is not Tcl, it is it's own language. Different syntax, different semantics.

-Brian
0 mensajes nuevos