• expr making something strange

    From Roderick@hruodr@gmail.com to comp.lang.tcl on Wed Aug 12 13:59:31 2026
    From Newsgroup: comp.lang.tcl


    % set ex 33/32
    33/32
    % expr {$ex}
    33/32

    % set a ttt
    ttt
    % expr {$a}
    ttt

    This happens wuth tcl8.6, tcl9.0 and jim.

    Any explanation?


    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Robert Heller@heller@deepsoft.com to comp.lang.tcl on Wed Aug 12 15:02:23 2026
    From Newsgroup: comp.lang.tcl

    At Wed, 12 Aug 2026 13:59:31 +0000 Roderick <hruodr@gmail.com> wrote:


    % set ex 33/32
    33/32
    % expr {$ex}
    33/32

    % set a ttt
    ttt
    % expr {$a}
    ttt

    This happens wuth tcl8.6, tcl9.0 and jim.

    Any explanation?
    This is perfectly normal. You are appearently not understanding how Tcl's "quoting" and evaluation works. And how expr itself works.
    marchhare% tclsh
    % set ex 33/32
    33/32
    % expr {$ex}
    33/32
    % expr $ex
    1
    % expr {33/32}
    1
    If you want to create an expression by some means other than "hard coding it" in the bracketed list given to expr, you have to strip off the brackets.
    This is possibly "dangerious" and should be used with caution, but there are proper use cases for doing this.
    % set a ttt
    ttt
    % expr {$a}
    ttt
    % expr $a
    invalid bareword "ttt"
    in expression "ttt";
    should be "$ttt" or "{ttt}" or "ttt(...)" or ...




    --
    Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
    Deepwoods Software -- Custom Software Services
    http://www.deepsoft.com/ -- Linux Administration Services
    heller@deepsoft.com -- Webhosting Services
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From saito@saitology9@gmail.com to comp.lang.tcl on Wed Aug 12 11:04:30 2026
    From Newsgroup: comp.lang.tcl

    On 8/12/2026 9:59 AM, Roderick wrote:

    % set ex 33/32
    33/32
    % expr {$ex}
    33/32

    % set a ttt
    ttt
    % expr {$a}
    ttt

    This happens wuth tcl8.6, tcl9.0 and jim.

    Any explanation?



    No question? I will assume you are wondering why "expr {$ex}" did not
    return 1. Because doing so will require doing double substitution.
    "expr" receives 33/32 as an operand, which is clearly not a recognized
    numeric entity. So it it simply returns it as-is. If you slightly change
    the syntax but not the semantics of your expression, you will see why
    more clearly:

    % expr {$a + 0}
    can't use non-numeric string as operand of "+"


    You can force a double substitution to get what you want:

    % expr [expr {$a}]
    1

    If you were asking something else, please rephrase it.
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Roderick@hruodr@gmail.com to comp.lang.tcl on Wed Aug 12 15:30:24 2026
    From Newsgroup: comp.lang.tcl


    On Wed, 12 Aug 2026, saito wrote:

    On 8/12/2026 9:59 AM, Roderick wrote:

    % set ex 33/32
    33/32
    % expr {$ex}
    33/32

    % set a ttt
    ttt
    % expr {$a}
    ttt

    This happens wuth tcl8.6, tcl9.0 and jim.

    Any explanation?

    No question? I will assume you are wondering why "expr {$ex}" did not return 1. Because doing so will require doing double substitution.

    But it is doing a substitution of the expression, similar as
    with scripts. Why it gives a string instead of an error?

    % expr {$a + 0}
    can't use non-numeric string as operand of "+"

    As for example here?

    And yes, it would be interesting if variable were substituted and then
    the resulting expression evaluated, as hapenps with "".
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From saito@saitology9@gmail.com to comp.lang.tcl on Wed Aug 12 11:44:56 2026
    From Newsgroup: comp.lang.tcl

    On 8/12/2026 11:30 AM, Roderick wrote:

    On Wed, 12 Aug 2026, saito wrote:

    No question? I will assume you are wondering why "expr {$ex}" did not
    return 1. Because doing so will require doing double substitution.

    But it is doing a substitution of the expression, similar as
    with scripts. Why it gives a string instead of an error?


    It did. But since it has no operators, it simply returns whatever it has
    so far.

    From the documentation:
    "Also, Tcl expressions support non-numeric operands and string
    comparisons, as well as some additional operators not found in C."



    % expr {$a + 0}
    can't use non-numeric string as operand of "+"

    As for example here?

    And yes, it would be interesting if variable were substituted and then
    the resulting expression evaluated, as hapenps with "".

    Again, it did. It tried to add string "33/32" and "0" and it complained because one argument was a string.




    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From saito@saitology9@gmail.com to comp.lang.tcl on Wed Aug 12 11:56:43 2026
    From Newsgroup: comp.lang.tcl

    On 8/12/2026 11:30 AM, Roderick wrote:

    On Wed, 12 Aug 2026, saito wrote:

    % expr {$a + 0}
    can't use non-numeric string as operand of "+"

    As for example here?

    And yes, it would be interesting if variable were substituted and then
    the resulting expression evaluated, as hapenps with "".

    I think the confusion may be that you see "33/32" as a value already,
    and not as a string.

    Perhaps expanding on your own example would be helpful:

    set a {33/32 + $pie - $slice}
    set pie 3.14
    set slice {$pie/4.0}

    So when you say, "expr {$a}" at what point do you want the substitutions
    to stop?




    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Roderick@hruodr@gmail.com to comp.lang.tcl on Wed Aug 12 20:29:50 2026
    From Newsgroup: comp.lang.tcl


    On Wed, 12 Aug 2026, saito wrote:

    I think the confusion may be that you see "33/32" as a value already, and not
    as a string.

    No, I do see it as a expression. The confussion is, what I said:
    I expected an error.


    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Roderick@hruodr@gmail.com to comp.lang.tcl on Wed Aug 12 20:33:31 2026
    From Newsgroup: comp.lang.tcl


    On Wed, 12 Aug 2026, saito wrote:

    So when you say, "expr {$a}" at what point do you want the substitutions to stop?

    The problem is, that I imagined such expression as similar to
    a script evaluation.

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Robert Heller@heller@deepsoft.com to comp.lang.tcl on Wed Aug 12 21:06:46 2026
    From Newsgroup: comp.lang.tcl

    At Wed, 12 Aug 2026 20:33:31 +0000 Roderick <hruodr@gmail.com> wrote:


    On Wed, 12 Aug 2026, saito wrote:

    So when you say, "expr {$a}" at what point do you want the substitutions to stop?

    The problem is, that I imagined such expression as similar to
    a script evaluation.
    It is not. expr is not the same as a "block" as you would have with proc, or for or while. And the varable subsitution happens after expression parsing, not before.
    The currly brackets supresses subsitution.
    Unlike LISP, which has different flavors of functions, where some get their arguments evaluated and some don't, Tcl's read-eval-loop *ALWAYS* "evaluates" (subsitutes) all arguments for all procs and commands. To get things like control "statements" to work (Tcl does not really have any statements, since all "commands" are just C coded procs), you wrap the defered script fragments with currly brackets ({}), and then the control statement commands call Tcl_Eval to "eval" the script fragments that were "protected" with the currly brackets. expr does something *similar*, but different. Tcl is generally a prefix language (like LISP), exccept expr in infix and has its own expression parser.



    --
    Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
    Deepwoods Software -- Custom Software Services
    http://www.deepsoft.com/ -- Linux Administration Services
    heller@deepsoft.com -- Webhosting Services
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From et99@et99@rocketship1.me to comp.lang.tcl on Wed Aug 12 15:41:21 2026
    From Newsgroup: comp.lang.tcl

    On 8/12/2026 1:29 PM, Roderick wrote:

    On Wed, 12 Aug 2026, saito wrote:

    I think the confusion may be that you see "33/32" as a value already, and not as a string.

    No, I do see it as a expression. The confussion is, what I said:
    I expected an error.




    To see why, look at the below disassemble, and then the code for that bytecode instruction tryCvtToNumeric,

    note the "is acceptable" comment:


    % set ex {5/4}
    5/4
    % expr {$ex}
    5/4
    % lds script {expr {$ex}}
    ...
    Command 1: "expr {$ex}"
    (0) push1 0 # "ex"
    (2) loadStk
    (3) tryCvtToNumeric
    (4) done




    case INST_TRY_CVT_TO_NUMERIC:
    /*
    * Try to convert the topmost stack object to numeric object. This is
    * done in order to support [expr]'s policy of interpreting operands
    * if at all possible as numbers first, then strings.
    */

    valuePtr = OBJ_AT_TOS;
    TRACE("\"%.20s\" => ", O2S(valuePtr));

    if (GetNumberFromObj(NULL, valuePtr, &ptr1, &type1) != TCL_OK) {
    if (*pc == INST_UPLUS) {
    /*
    * ... +$NonNumeric => raise an error.
    */

    TRACE_APPEND("ERROR: illegal type %s\n",
    TY2S(valuePtr->typePtr));
    DECACHE_STACK_INFO();
    IllegalExprOperandType(interp, "", pc, valuePtr);
    CACHE_STACK_INFO();
    goto gotError;
    }

    /* ... TryConvertToNumeric($NonNumeric) is acceptable */
    TRACE_APPEND("not numeric\n");
    NEXT_INST_F0(1, 0);
    }



    -et

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Roderick@hruodr@gmail.com to comp.lang.tcl on Thu Aug 13 06:55:58 2026
    From Newsgroup: comp.lang.tcl


    On Wed, 12 Aug 2026, Robert Heller wrote:

    ... And the varable subsitution happens after expression parsing,
    not before.

    The currly brackets supresses subsitution.

    Here is not being suppressed:

    % set a ttt; expr {$a}
    ttt

    And after parsing should follow evaluation, here should be an error.

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Roderick@hruodr@gmail.com to comp.lang.tcl on Thu Aug 13 07:18:21 2026
    From Newsgroup: comp.lang.tcl



    On Wed, 12 Aug 2026, et99 wrote:

    To see why, look at the below disassemble, and then the code for that bytecode instruction tryCvtToNumeric,

    note the "is acceptable" comment:

    Thanks! From where you have the command lds?
    It does not exist in my tclsh

    R.



    % set ex {5/4}
    5/4
    % expr {$ex}
    5/4
    % lds script {expr {$ex}}
    ...
    Command 1: "expr {$ex}"
    (0) push1 0 # "ex"
    (2) loadStk
    (3) tryCvtToNumeric
    (4) done




    case INST_TRY_CVT_TO_NUMERIC:
    /*
    * Try to convert the topmost stack object to numeric object. This is
    * done in order to support [expr]'s policy of interpreting operands
    * if at all possible as numbers first, then strings.
    */

    valuePtr = OBJ_AT_TOS;
    TRACE("\"%.20s\" => ", O2S(valuePtr));

    if (GetNumberFromObj(NULL, valuePtr, &ptr1, &type1) != TCL_OK) {
    if (*pc == INST_UPLUS) {
    /*
    * ... +$NonNumeric => raise an error.
    */

    TRACE_APPEND("ERROR: illegal type %s\n",
    TY2S(valuePtr->typePtr));
    DECACHE_STACK_INFO();
    IllegalExprOperandType(interp, "", pc, valuePtr);
    CACHE_STACK_INFO();
    goto gotError;
    }

    /* ... TryConvertToNumeric($NonNumeric) is acceptable */
    TRACE_APPEND("not numeric\n");
    NEXT_INST_F0(1, 0);
    }



    -et


    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Robert Heller@heller@deepsoft.com to comp.lang.tcl on Thu Aug 13 11:55:15 2026
    From Newsgroup: comp.lang.tcl

    At Thu, 13 Aug 2026 06:55:58 +0000 Roderick <hruodr@gmail.com> wrote:


    On Wed, 12 Aug 2026, Robert Heller wrote:

    ... And the varable subsitution happens after expression parsing,
    not before.

    The currly brackets supresses subsitution.

    Here is not being suppressed:

    % set a ttt; expr {$a}
    ttt
    Yes it is. *Expr* itself is doing the eval, not the read-eval-loop.
    Compare to this:
    % set a ttt; expr $a
    invalid bareword "ttt"
    in expression "ttt";
    should be "$ttt" or "{ttt}" or "ttt(...)" or ...

    And after parsing should follow evaluation, here should be an error.
    Yes. That is what does happen.
    You are still confused bt what the currly brackets (braces) are doing.



    --
    Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
    Deepwoods Software -- Custom Software Services
    http://www.deepsoft.com/ -- Linux Administration Services
    heller@deepsoft.com -- Webhosting Services
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Robert Heller@heller@deepsoft.com to comp.lang.tcl on Thu Aug 13 11:55:19 2026
    From Newsgroup: comp.lang.tcl

    At Thu, 13 Aug 2026 07:18:21 +0000 Roderick <hruodr@gmail.com> wrote:



    On Wed, 12 Aug 2026, et99 wrote:

    To see why, look at the below disassemble, and then the code for that bytecode instruction tryCvtToNumeric,

    note the "is acceptable" comment:

    Thanks! From where you have the command lds?
    It does not exist in my tclsh
    It requires a special build option, not normal for production builds.

    R.



    % set ex {5/4}
    5/4
    % expr {$ex}
    5/4
    % lds script {expr {$ex}}
    ...
    Command 1: "expr {$ex}"
    (0) push1 0 # "ex"
    (2) loadStk
    (3) tryCvtToNumeric
    (4) done




    case INST_TRY_CVT_TO_NUMERIC:
    /*
    * Try to convert the topmost stack object to numeric object. This is
    * done in order to support [expr]'s policy of interpreting operands
    * if at all possible as numbers first, then strings.
    */

    valuePtr = OBJ_AT_TOS;
    TRACE("\"%.20s\" => ", O2S(valuePtr));

    if (GetNumberFromObj(NULL, valuePtr, &ptr1, &type1) != TCL_OK) {
    if (*pc == INST_UPLUS) {
    /*
    * ... +$NonNumeric => raise an error.
    */

    TRACE_APPEND("ERROR: illegal type %s\n",
    TY2S(valuePtr->typePtr));
    DECACHE_STACK_INFO();
    IllegalExprOperandType(interp, "", pc, valuePtr);
    CACHE_STACK_INFO();
    goto gotError;
    }

    /* ... TryConvertToNumeric($NonNumeric) is acceptable */
    TRACE_APPEND("not numeric\n");
    NEXT_INST_F0(1, 0);
    }



    -et




    --
    Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
    Deepwoods Software -- Custom Software Services
    http://www.deepsoft.com/ -- Linux Administration Services
    heller@deepsoft.com -- Webhosting Services
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Roderick@hruodr@gmail.com to comp.lang.tcl on Thu Aug 13 12:58:42 2026
    From Newsgroup: comp.lang.tcl


    On Thu, 13 Aug 2026, Robert Heller wrote:

    At Thu, 13 Aug 2026 06:55:58 +0000 Roderick <hruodr@gmail.com> wrote:


    On Wed, 12 Aug 2026, Robert Heller wrote:

    ... And the varable subsitution happens after expression parsing,
    not before.

    The currly brackets supresses subsitution.

    Here is not being suppressed:

    % set a ttt; expr {$a}
    ttt

    Yes it is. *Expr* itself is doing the eval, not the read-eval-loop.

    I quote your previous message:

    "" It is not. expr is not the same as a "block" as you would have with
    proc, or for or while.""


    Compare to this:

    % set a ttt; expr $a
    invalid bareword "ttt"
    in expression "ttt";
    should be "$ttt" or "{ttt}" or "ttt(...)" or ...

    No, I do not compare to that, the thema is, why "% set a ttt; expr {$a}"
    does not give an error message and do evaluate $a.

    And after parsing should follow evaluation, here should be an error.

    Yes. That is what does happen.

    After you changed the expression to one that gives error message.


    You are still confused bt what the currly brackets (braces) are doing.

    Excuse me, I use tcl since year 2000, I programnmed thoousands of tcl
    lines.

    I suspect, you are the one confused.

    et99 gave a short and clear answer, why it does not give an error message:
    an "if" in the source code.

    You are making confusing philosophy of curl braces instead.


    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Robert Heller@heller@deepsoft.com to comp.lang.tcl on Thu Aug 13 13:00:07 2026
    From Newsgroup: comp.lang.tcl

    I think part of what is confusing you is this fact:
    Tcl *DOES NOT* have a [sematic] parser, This is something Tcl shares with LISP. Almost all other programming languages have a [sematic] parser:
    FORTRAN, BASIC, COBOL, Algol / Pascal, C / C++, Java, rust, and many others. For these languages an "if" statement (for example) is something defined in a standard somewhere and is something programmers can count on to have a well documented structure.
    Tcl, like LISP, does not have a set of "statements", each with a specific "syntax". *Everything* [that does anything] in Tcl (like LISP) is a just a "function". Period. Tcl does not have "if" *statements* (in the sense that C has "if" statements). Tcl just has a *function* (coded in C) named "if". The sematics is implemented in the if *function*, there is no specific parse logic for "if" or really ANY other "control flow" operation. One can easily define
    a proc that completely redefines what "if" looks like, or define completely
    new "control flow" functions.
    In LISP there are two main types of functions: those where the arguments are evaluated before being passed and those that are NOT evaluated before being passed. LISP's "control flow" functions (like cond) are functions where the argument evaluation is "supressed" and these functions call evel internally. With Tcl, all arguments are evaluated (subsituted) before being passed.
    Always. The currly brackets (braces) suppress evaluation (subsitutation)
    before passing. Really, what is happening is the braces are a kind of quoting, which happens to work across newlines, so they "look" like and seem to behave like braces in C. But they are not really anything like braces in C. Even when that is what it *looks* like.
    Something similar is happening with expr. The braces in the argument to expr are not a syntacic "feature" of expr, but a way of "quoting" the argument to expr to prevent pre-mature "evaluation" (subsitutation) of the argument(s) to expr. This is done to "defer" evaluation (subsitutation) until *after* expr parses the expression, becaue expr itself will perform the evaluation (subsitutation) itself (eg it calls Tcl_Eval).
    At Thu, 13 Aug 2026 06:55:58 +0000 Roderick <hruodr@gmail.com> wrote:


    On Wed, 12 Aug 2026, Robert Heller wrote:

    ... And the varable subsitution happens after expression parsing,
    not before.

    The currly brackets supresses subsitution.

    Here is not being suppressed:

    % set a ttt; expr {$a}
    ttt

    And after parsing should follow evaluation, here should be an error.



    --
    Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
    Deepwoods Software -- Custom Software Services
    http://www.deepsoft.com/ -- Linux Administration Services
    heller@deepsoft.com -- Webhosting Services
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Roderick@hruodr@gmail.com to comp.lang.tcl on Thu Aug 13 13:29:28 2026
    From Newsgroup: comp.lang.tcl

    This message is in MIME format. The first part should be readable text,
    while the remaining parts are likely unreadable without MIME-aware tools.

    --2827311070-2584305-1786627771=:1647
    Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE


    To make this discussion more objective, I fed claud with the post bellow
    and asked:

    "Is this guy answering what at the end is quoted? Please, short answer."

    Answer from Claude:

    "No =E2=80=94 he restates his general theory about braces/quoting and defer= red=20
    substitution, but doesn't actually address Roderick's specific example=20
    (expr {$a} returning ttt instead of erroring)."

    Rod.


    On Thu, 13 Aug 2026, Robert Heller wrote:

    I think part of what is confusing you is this fact:

    Tcl *DOES NOT* have a [sematic] parser, This is something Tcl shares wit=
    h
    LISP. Almost all other programming languages have a [sematic] parser: FORTRAN, BASIC, COBOL, Algol / Pascal, C / C++, Java, rust, and many othe=
    rs.
    For these languages an "if" statement (for example) is something defined =
    in a
    standard somewhere and is something programmers can count on to have a we=
    ll
    documented structure.

    Tcl, like LISP, does not have a set of "statements", each with a specific "syntax". *Everything* [that does anything] in Tcl (like LISP) is a just=
    a
    "function". Period. Tcl does not have "if" *statements* (in the sense t=
    hat C
    has "if" statements). Tcl just has a *function* (coded in C) named "if".=
    The
    sematics is implemented in the if *function*, there is no specific parse =
    logic
    for "if" or really ANY other "control flow" operation. One can easily de=
    fine
    a proc that completely redefines what "if" looks like, or define complete=
    ly
    new "control flow" functions.

    In LISP there are two main types of functions: those where the arguments =
    are
    evaluated before being passed and those that are NOT evaluated before bei=
    ng
    passed. LISP's "control flow" functions (like cond) are functions where =
    the
    argument evaluation is "supressed" and these functions call evel internal=
    ly.

    With Tcl, all arguments are evaluated (subsituted) before being passed. Always. The currly brackets (braces) suppress evaluation (subsitutation) before passing. Really, what is happening is the braces are a kind of quo=
    ting,
    which happens to work across newlines, so they "look" like and seem to be=
    have
    like braces in C. But they are not really anything like braces in C. Even=
    when
    that is what it *looks* like.

    Something similar is happening with expr. The braces in the argument to e=
    xpr
    are not a syntacic "feature" of expr, but a way of "quoting" the argument=
    to
    expr to prevent pre-mature "evaluation" (subsitutation) of the argument(s=
    ) to
    expr. This is done to "defer" evaluation (subsitutation) until *after* ex=
    pr
    parses the expression, becaue expr itself will perform the evaluation (subsitutation) itself (eg it calls Tcl_Eval).


    At Thu, 13 Aug 2026 06:55:58 +0000 Roderick <hruodr@gmail.com> wrote:



    On Wed, 12 Aug 2026, Robert Heller wrote:

    ... And the varable subsitution happens after expression parsing,
    not before.

    The currly brackets supresses subsitution.

    Here is not being suppressed:

    % set a ttt; expr {$a}
    ttt

    And after parsing should follow evaluation, here should be an error.




    --
    Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
    Deepwoods Software -- Custom Software Services http://www.deepsoft.com/ -- Linux Administration Services heller@deepsoft.com -- Webhosting Services

    --2827311070-2584305-1786627771=:1647--
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Roderick@hruodr@gmail.com to comp.lang.tcl on Thu Aug 13 13:33:07 2026
    From Newsgroup: comp.lang.tcl

    This message is in MIME format. The first part should be readable text,
    while the remaining parts are likely unreadable without MIME-aware tools.

    --2827311070-695966110-1786627989=:1651
    Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE


    And then, I fed Claude with et99's posting and asked:

    "And et99's posting?"

    Answer from Claude:

    "Yes =E2=80=94 et99 directly addresses Roderick's point (expecting an error=
    for=20
    expr {$ex}) by showing the actual bytecode disassembly, demonstrating that=
    =20
    expr tries to convert to numeric but falls back to treating it as a string=
    =20
    ("not numeric") rather than erroring =E2=80=94 which explains why no error = occurs,=20
    unlike Heller's more general/evasive answer."

    Rod.


    On Thu, 13 Aug 2026, Roderick wrote:


    To make this discussion more objective, I fed claud with the post bellow
    and asked:

    "Is this guy answering what at the end is quoted? Please, short answer."

    Answer from Claude:

    "No =E2=80=94 he restates his general theory about braces/quoting and def=
    erred=20
    substitution, but doesn't actually address Roderick's specific example (e=
    xpr=20
    {$a} returning ttt instead of erroring)."

    Rod.


    On Thu, 13 Aug 2026, Robert Heller wrote:

    I think part of what is confusing you is this fact:
    =20
    Tcl *DOES NOT* have a [sematic] parser, This is something Tcl shares wi=
    th
    LISP. Almost all other programming languages have a [sematic] parser:
    FORTRAN, BASIC, COBOL, Algol / Pascal, C / C++, Java, rust, and many=20
    others.
    For these languages an "if" statement (for example) is something defined=
    in=20
    a
    standard somewhere and is something programmers can count on to have a w= ell
    documented structure.
    =20
    Tcl, like LISP, does not have a set of "statements", each with a specifi=
    c
    "syntax". *Everything* [that does anything] in Tcl (like LISP) is a jus=
    t a
    "function". Period. Tcl does not have "if" *statements* (in the sense=
    =20
    that C
    has "if" statements). Tcl just has a *function* (coded in C) named "if"= =2E=20
    The
    sematics is implemented in the if *function*, there is no specific parse= =20
    logic
    for "if" or really ANY other "control flow" operation. One can easily=
    =20
    define
    a proc that completely redefines what "if" looks like, or define complet= ely
    new "control flow" functions.
    =20
    In LISP there are two main types of functions: those where the arguments= =20
    are
    evaluated before being passed and those that are NOT evaluated before be= ing
    passed. LISP's "control flow" functions (like cond) are functions where= =20
    the
    argument evaluation is "supressed" and these functions call evel=20
    internally.
    =20
    With Tcl, all arguments are evaluated (subsituted) before being passed.
    Always. The currly brackets (braces) suppress evaluation (subsitutation)
    before passing. Really, what is happening is the braces are a kind of=20
    quoting,
    which happens to work across newlines, so they "look" like and seem to=
    =20
    behave
    like braces in C. But they are not really anything like braces in C. Eve= n=20
    when
    that is what it *looks* like.
    =20
    Something similar is happening with expr. The braces in the argument to=
    =20
    expr
    are not a syntacic "feature" of expr, but a way of "quoting" the argumen= t=20
    to
    expr to prevent pre-mature "evaluation" (subsitutation) of the argument(= s)=20
    to
    expr. This is done to "defer" evaluation (subsitutation) until *after* e= xpr
    parses the expression, becaue expr itself will perform the evaluation
    (subsitutation) itself (eg it calls Tcl_Eval).
    =20
    =20
    At Thu, 13 Aug 2026 06:55:58 +0000 Roderick <hruodr@gmail.com> wrote:
    =20
    =20
    =20
    On Wed, 12 Aug 2026, Robert Heller wrote:
    =20
    ... And the varable subsitution happens after expression parsing,
    not before.
    =20
    The currly brackets supresses subsitution.
    =20
    Here is not being suppressed:
    =20
    % set a ttt; expr {$a}
    ttt
    =20
    And after parsing should follow evaluation, here should be an error.
    =20
    =20
    =20
    =20
    --
    Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
    Deepwoods Software -- Custom Software Services
    http://www.deepsoft.com/ -- Linux Administration Services
    heller@deepsoft.com -- Webhosting Services

    --2827311070-695966110-1786627989=:1651--
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Robert Heller@heller@deepsoft.com to comp.lang.tcl on Thu Aug 13 13:57:43 2026
    From Newsgroup: comp.lang.tcl

    Why do you think
    set a "ttt";expr {$a}
    should return an error?
    An expression containing a single variable reference is a perfectly valid expression and results in the variable's value, nothing more. What error message did you expect? If you are expecting an error complaining that "ttt" is an invalid expression, that is what you get when you leave off the braces:
    set a "ttt";expr $a
    Expr behaves *exactly* as expected.
    Your *original* form:
    set a "33/32"; expr {$a}
    just returns the string "33/32" and not 33 divided by 32 (integer value 1) and I think this is what originally confused you. The confusion is understandable if one does not *fully* understand just what the braces are doing. So I tried to explained what the braces are doing.
    It is enirely possible to code successfully in Tcl without fully understanding what the braces really are and still be supprised when something "unexpected" happens. In my case I learned LISP *before* Tcl, so I was throughly exposed
    to what is effectly one of the underlying features of Tcl, one that many users of Tcl don't actually get.
    And Claude, like all LLMs are total idiots, Don't expect it to give you any really good in-depth answers. Especially for this sort of question.
    At Thu, 13 Aug 2026 13:29:28 +0000 Roderick <hruodr@gmail.com> wrote:


    To make this discussion more objective, I fed claud with the post bellow
    and asked:

    "Is this guy answering what at the end is quoted? Please, short answer."

    Answer from Claude:

    "No |o-C-o he restates his general theory about braces/quoting and deferred substitution, but doesn't actually address Roderick's specific example
    (expr {$a} returning ttt instead of erroring)."

    Rod.


    On Thu, 13 Aug 2026, Robert Heller wrote:

    I think part of what is confusing you is this fact:

    Tcl *DOES NOT* have a [sematic] parser, This is something Tcl shares with LISP. Almost all other programming languages have a [sematic] parser: FORTRAN, BASIC, COBOL, Algol / Pascal, C / C++, Java, rust, and many others.
    For these languages an "if" statement (for example) is something defined in a
    standard somewhere and is something programmers can count on to have a well documented structure.

    Tcl, like LISP, does not have a set of "statements", each with a specific "syntax". *Everything* [that does anything] in Tcl (like LISP) is a just a "function". Period. Tcl does not have "if" *statements* (in the sense that C
    has "if" statements). Tcl just has a *function* (coded in C) named "if". The
    sematics is implemented in the if *function*, there is no specific parse logic
    for "if" or really ANY other "control flow" operation. One can easily define
    a proc that completely redefines what "if" looks like, or define completely new "control flow" functions.

    In LISP there are two main types of functions: those where the arguments are
    evaluated before being passed and those that are NOT evaluated before being passed. LISP's "control flow" functions (like cond) are functions where the
    argument evaluation is "supressed" and these functions call evel internally.

    With Tcl, all arguments are evaluated (subsituted) before being passed. Always. The currly brackets (braces) suppress evaluation (subsitutation) before passing. Really, what is happening is the braces are a kind of quoting,
    which happens to work across newlines, so they "look" like and seem to behave
    like braces in C. But they are not really anything like braces in C. Even when
    that is what it *looks* like.

    Something similar is happening with expr. The braces in the argument to expr
    are not a syntacic "feature" of expr, but a way of "quoting" the argument to
    expr to prevent pre-mature "evaluation" (subsitutation) of the argument(s) to
    expr. This is done to "defer" evaluation (subsitutation) until *after* expr parses the expression, becaue expr itself will perform the evaluation (subsitutation) itself (eg it calls Tcl_Eval).


    At Thu, 13 Aug 2026 06:55:58 +0000 Roderick <hruodr@gmail.com> wrote:



    On Wed, 12 Aug 2026, Robert Heller wrote:

    ... And the varable subsitution happens after expression parsing,
    not before.

    The currly brackets supresses subsitution.

    Here is not being suppressed:

    % set a ttt; expr {$a}
    ttt

    And after parsing should follow evaluation, here should be an error.




    --
    Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
    Deepwoods Software -- Custom Software Services http://www.deepsoft.com/ -- Linux Administration Services heller@deepsoft.com -- Webhosting Services


    --
    Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
    Deepwoods Software -- Custom Software Services
    http://www.deepsoft.com/ -- Linux Administration Services
    heller@deepsoft.com -- Webhosting Services
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Roderick@hruodr@gmail.com to comp.lang.tcl on Thu Aug 13 14:38:56 2026
    From Newsgroup: comp.lang.tcl


    On Thu, 13 Aug 2026, Robert Heller wrote:

    Why do you think

    set a "ttt";expr {$a}

    should return an error?

    An expression containing a single variable reference is a perfectly valid expression and results in the variable's value, nothing more. What error message did you expect?

    An analogue expresion that do bring an error:

    % set a "ttt";expr {$a+0}
    can't use non-numeric string as operand of "+"

    "expr {$a+0}" does not do cumpter algebra, but "expr {$a}" does.


    If you are expecting an error complaining that "ttt" is
    an invalid expression, that is what you get when you leave off the braces:

    The question is not about writing an expression that brings an error.
    I told you that before.


    I think this is what originally confused you.

    What "confused" me was incosistent behavior. et99 showed from where it
    comes: it is artificially introduced in the source code with an if.
    The only question that remains: why tcl and jim are doing it.


    The confusion is understandable if one does not *fully* understand just
    what the braces are doing.

    If you do not undertand what is the problem I was pointing to, you cannot
    say "the confusion is understandable".


    So I tried to explained what the braces are doing.

    Please, never try to explain things you do not understand.


    It is enirely possible to code successfully in Tcl without fully understanding
    what the braces really are and still be supprised when something "unexpected" happens.

    The issue is not about the braces.


    In my case I learned LISP *before* Tcl,

    I also.


    And Claude, like all LLMs are total idiots, Don't expect it to give you any really good in-depth answers. Especially for this sort of question.

    Claude just confirmed what I told you: et99 answered my question, you did
    not. I really cannot call Claude under this circumstances "total idiot".
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Robert Heller@heller@deepsoft.com to comp.lang.tcl on Thu Aug 13 15:05:38 2026
    From Newsgroup: comp.lang.tcl

    At Thu, 13 Aug 2026 14:38:56 +0000 Roderick <hruodr@gmail.com> wrote:


    On Thu, 13 Aug 2026, Robert Heller wrote:

    Why do you think

    set a "ttt";expr {$a}

    should return an error?

    An expression containing a single variable reference is a perfectly valid expression and results in the variable's value, nothing more. What error message did you expect?

    An analogue expresion that do bring an error:

    % set a "ttt";expr {$a+0}
    can't use non-numeric string as operand of "+"

    "expr {$a+0}" does not do cumpter algebra, but "expr {$a}" does.
    "computer algebra"? What is that? I'm guessing English is not your first language?
    '$a+0' is an *arithmetic* expression, specificly addition and since $a does
    not evaluate to a numerical value, the expression results in an error.
    '$a' is not an arithmetic expression. It is just a term. The fact that $a
    does not evaluate to a numerical value is not relevant. In Tcl "everything is a string", so $a not being a number is not an issue. There is nothing inconsistant here. Expr is not required to return a numercial value.
    Consider:
    marchhare% tclsh
    % set a 4
    4
    % expr {$a % 2 == 1 ? "$a is odd" : "$a is even"}
    4 is even


    If you are expecting an error complaining that "ttt" is
    an invalid expression, that is what you get when you leave off the braces:

    The question is not about writing an expression that brings an error.
    I told you that before.


    I think this is what originally confused you.

    What "confused" me was incosistent behavior. et99 showed from where it
    comes: it is artificially introduced in the source code with an if.
    The only question that remains: why tcl and jim are doing it.
    Exactly what "inconsistent behavior"? You have never really explained what that was. I don't see anything inconsistent.


    The confusion is understandable if one does not *fully* understand just what the braces are doing.

    If you do not undertand what is the problem I was pointing to, you cannot
    say "the confusion is understandable".


    So I tried to explained what the braces are doing.

    Please, never try to explain things you do not understand.


    It is enirely possible to code successfully in Tcl without fully understanding
    what the braces really are and still be supprised when something "unexpected"
    happens.

    The issue is not about the braces.


    In my case I learned LISP *before* Tcl,

    I also.


    And Claude, like all LLMs are total idiots, Don't expect it to give you any
    really good in-depth answers. Especially for this sort of question.

    Claude just confirmed what I told you: et99 answered my question, you did not. I really cannot call Claude under this circumstances "total idiot".


    --
    Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
    Deepwoods Software -- Custom Software Services
    http://www.deepsoft.com/ -- Linux Administration Services
    heller@deepsoft.com -- Webhosting Services
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Roderick@hruodr@gmail.com to comp.lang.tcl on Thu Aug 13 15:22:27 2026
    From Newsgroup: comp.lang.tcl


    On Thu, 13 Aug 2026, Robert Heller wrote:

    "computer algebra"? What is that? I'm guessing English is not your first language?

    Never heard of maxima/macsyma and reduce, very old LISP programs?

    https://en.wikipedia.org/wiki/Computer_algebra

    inconsistant here. Expr is not required to return a numercial value.

    Consider:

    marchhare% tclsh
    % set a 4
    4
    % expr {$a % 2 = 1 ? "$a is odd" : "$a is even"}
    4 is even

    New to me. That means, there are more acceptable non numeric expressions.
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Robert Heller@heller@deepsoft.com to comp.lang.tcl on Thu Aug 13 15:38:31 2026
    From Newsgroup: comp.lang.tcl

    At Thu, 13 Aug 2026 15:22:27 +0000 Roderick <hruodr@gmail.com> wrote:


    On Thu, 13 Aug 2026, Robert Heller wrote:

    "computer algebra"? What is that? I'm guessing English is not your first language?

    Never heard of maxima/macsyma and reduce, very old LISP programs?

    https://en.wikipedia.org/wiki/Computer_algebra

    inconsistant here. Expr is not required to return a numercial value.

    Consider:

    marchhare% tclsh
    % set a 4
    4
    % expr {$a % 2 = 1 ? "$a is odd" : "$a is even"}
    4 is even

    New to me. That means, there are more acceptable non numeric expressions.
    Right. Expr has no requirement that expression terms be numerical and is not presumed to return a numerical result. Remember the Tcl mantra: "everything is a string". So there is nothing inconsistant about expr returning a string and not complaining when given an expression that evaluates to a string, even when the expression is a simple term. This might be unique to Tcl, but such is the nature of things.


    --
    Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
    Deepwoods Software -- Custom Software Services
    http://www.deepsoft.com/ -- Linux Administration Services
    heller@deepsoft.com -- Webhosting Services
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Ralf Fassel@ralfixx@gmx.de to comp.lang.tcl on Thu Aug 13 17:45:49 2026
    From Newsgroup: comp.lang.tcl

    * Roderick <hruodr@gmail.com>
    | On Thu, 13 Aug 2026, Robert Heller wrote:

    | > Why do you think
    | >
    | > set a "ttt";expr {$a}
    | >
    | > should return an error?
    | >
    | > An expression containing a single variable reference is a perfectly valid
    | > expression and results in the variable's value, nothing more. What error
    | > message did you expect?

    | An analogue expresion that do bring an error:

    | % set a "ttt";expr {$a+0}
    | can't use non-numeric string as operand of "+"

    | "expr {$a+0}" does not do cumpter algebra, but "expr {$a}" does.

    You need to consider what 'expr' actually 'sees', and the rules how 'expr' evaluates what it sees.

    set a 33/32

    - expr {$a}
    => due to the braces around $a, the value of variable a is NOT substituted by
    the TCL parser, and expr actually sees "$a" (2 characters '$' 'a')
    => now expr operand rule [3] kicks in:
    [3] As a Tcl variable, using standard $ notation. The variable's
    value will be used as the operand.
    => expr substitues the $a by its contents "33/32"
    => since there is nothing else in the expression, this is the
    final expressions result (it is *not* evaluated again to yield 1).
    ---------------------

    - expr {$a+0}
    => again, as above, no substitution by the TCL parser,
    expr sees the string "$a+0" (4 characters '$' 'a' '+' '0')
    => the first two ($a) again are resolved by rule [3], yielding "33/32"
    (note that there is no second round of evaluation here to split this
    further into "33" "/" "32")
    => the next one is an operator "+"
    => the next on is a literal number (rule [1])

    Now the complete expression to evaluate is

    "33/32" "+" "0"

    The first operand "33/32" now does not match any of the allowed formats
    [1]-[7] for operands of TCL expressions, thus an error is thrown.
    ---------------------

    - expr "$a+0"
    => now due to the "" the variable *is* substituted by the TCL parser
    *before* calling expr
    => expr sees "33/32+0"
    - first operand is number: 33
    - second is operator: /
    - third is number: 32
    - fourth is operator: +
    - fifth is number: 0
    => everything matches an allowed item for TCL expressions and can be evaluated.
    ---------------------

    HTH
    R'
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Ralf Fassel@ralfixx@gmx.de to comp.lang.tcl on Thu Aug 13 17:49:16 2026
    From Newsgroup: comp.lang.tcl

    * Ralf Fassel <ralfixx@gmx.de>
    | Now the complete expression to evaluate is
    |
    | "33/32" "+" "0"

    | The first operand "33/32" now does not match any of the allowed formats
    | [1]-[7] for operands of TCL expressions, thus an error is thrown.
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    Grrr....
    Make that "for operands of TCL *arithmetic* expressions".

    :-)
    R'
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From saito@saitology9@gmail.com to comp.lang.tcl on Thu Aug 13 11:56:58 2026
    From Newsgroup: comp.lang.tcl

    On 8/13/2026 9:33 AM, Roderick wrote:

    And then, I fed Claude with et99's posting and asked:

    "And-a et99's posting?"

    Answer from Claude:

    "Yes rCo et99 directly addresses Roderick's point (expecting an error for expr {$ex}) by showing the actual bytecode disassembly, demonstrating
    that expr tries to convert to numeric but falls back to treating it as a string ("not numeric") rather than erroring rCo which explains why no
    error occurs, unlike Heller's more general/evasive answer."

    ......
    Claude just confirmed what I told you: et99 answered my question,
    you did
    not. I really cannot call Claude under this circumstances "total idiot".


    Two points:

    One, please be respectful, especially to people trying to help you.


    Second, perhaps you could also ask Claude whether I answered your
    implicit question on day one, and what you needed to learn that you
    hadn't since 2000. (While lds is useful, it only validated these
    statements.)

    This:>
    It did. But since it has no operators, it simply returns
    whatever it has so far.


    Plus:> If you slightly change the syntax but not the semantics of your expression, you will see why more clearly:

    % expr {$a + 0}
    can't use non-numeric string as operand of "+"

    Plus:> From the documentation:
    "Also, Tcl expressions support non-numeric operands and string
    comparisons, as well as some additional operators not found in C."

    And more...



    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Roderick@hruodr@gmail.com to comp.lang.tcl on Thu Aug 13 16:58:30 2026
    From Newsgroup: comp.lang.tcl


    On Thu, 13 Aug 2026, saito wrote:

    One, please be respectful, especially to people trying to help you.

    Well, I was a little disgusted that the thema turned insistent to be
    my "confussion" followed by long confuse explanations. I just wanted to
    stop the trend.

    I think, now is all clear.

    Second, perhaps you could also ask Claude whether I answered your implicit question on day one,

    You explanation was an explanation, but needed a very little more,
    Ralf Fassel brought it. While I really like short explanations, yours
    was too short. There is no need to ask Claude. You can try. I just
    copied each time a posting and asked.

    and what you needed to learn that you hadn't since 2000.

    I used expr a lot, but always as a numerical calculator, so that
    I was never confronted with this issue. I never needed expr to
    do something with strings.

    All these problems began after I wraped jim in sqlite to have
    three new sqlite3 functions to apply on columns:
    expr (Jim_EvalExpression),
    jim (Jim_Eval),
    jimv (Jim_EvalObjVector).

    R.

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From saito@saitology9@gmail.com to comp.lang.tcl on Thu Aug 13 13:04:00 2026
    From Newsgroup: comp.lang.tcl

    On 8/13/2026 12:58 PM, Roderick wrote:

    On Thu, 13 Aug 2026, saito wrote:

    One, please be respectful, especially to people trying to help you.

    Well, I was a little disgusted that the thema turned insistent to be
    my "confussion" followed by long confuse explanations. I just wanted to
    stop the trend.

    I think, now is all clear.


    This is a nice summary. Thanks.
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From et99@et99@rocketship1.me to comp.lang.tcl on Thu Aug 13 14:03:30 2026
    From Newsgroup: comp.lang.tcl

    On 8/13/2026 12:18 AM, Roderick wrote:


    Thanks! From where you have the command lds?
    It does not exist in my tclsh



    Oh, sorry, I forgot, I have an alias lds, the real command is:


    tcl::unsupported::disassemble


    1 % tcl::unsupported::disassemble
    wrong # args: should be "tcl::unsupported::disassemble type ..."
    2 % tcl::unsupported::disassemble xxx
    bad type "xxx": must be constructor, destructor, lambda, method, objmethod, proc, or script


    -et

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Ralf Fassel@ralfixx@gmx.de to comp.lang.tcl on Fri Aug 14 11:09:54 2026
    From Newsgroup: comp.lang.tcl

    * Roderick <hruodr@gmail.com>
    | I used expr a lot, but always as a numerical calculator, so that
    | I was never confronted with this issue. I never needed expr to
    | do something with strings.

    Whenever you code something like

    if {$a ne $b} ... (note: "ne", not "!=")

    you're using the "string expr".

    NB. All of the discussion in this thread holds for 'if' as well.
    You can brace the conditional expression for 'if', or you can double
    quote it, with the same consequences as for 'expr'.

    R'
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Roderick@hruodr@gmail.com to comp.lang.tcl on Fri Aug 14 09:51:11 2026
    From Newsgroup: comp.lang.tcl


    On Fri, 14 Aug 2026, Ralf Fassel wrote:

    * Roderick <hruodr@gmail.com>
    | I used expr a lot, but always as a numerical calculator, so that
    | I was never confronted with this issue. I never needed expr to
    | do something with strings.

    Whenever you code something like

    if {$a ne $b} ... (note: "ne", not "!=")

    you're using the "string expr".

    Yes, I wanted to say: to obtain numbers with expr.

    There was a time that I used [string equal $a $b] for that.

    I think, eq and ne in expr appeared at some point, or I did not knew them.

    R.
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Roderick@hruodr@gmail.com to comp.lang.tcl on Fri Aug 14 10:00:49 2026
    From Newsgroup: comp.lang.tcl


    On Fri, 14 Aug 2026, Ralf Fassel wrote:

    NB. All of the discussion in this thread holds for 'if' as well.
    You can brace the conditional expression for 'if', or you can double
    quote it, with the same consequences as for 'expr'.

    Look:

    % set a test
    test
    % expr {$a}
    test
    % if {$a} {return 1} else {return 0}
    expected boolean value but got "test"

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Robert Heller@heller@deepsoft.com to comp.lang.tcl on Fri Aug 14 12:04:52 2026
    From Newsgroup: comp.lang.tcl

    At Fri, 14 Aug 2026 10:00:49 +0000 Roderick <hruodr@gmail.com> wrote:


    On Fri, 14 Aug 2026, Ralf Fassel wrote:

    NB. All of the discussion in this thread holds for 'if' as well.
    You can brace the conditional expression for 'if', or you can double
    quote it, with the same consequences as for 'expr'.

    Look:

    % set a test
    test
    % expr {$a}
    test
    % if {$a} {return 1} else {return 0}
    expected boolean value but got "test"



    And also:
    % set a yes
    yes
    % if {$a} {return 1} else {return 0}
    1
    --
    Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
    Deepwoods Software -- Custom Software Services
    http://www.deepsoft.com/ -- Linux Administration Services
    heller@deepsoft.com -- Webhosting Services
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Ralf Fassel@ralfixx@gmx.de to comp.lang.tcl on Fri Aug 14 15:06:50 2026
    From Newsgroup: comp.lang.tcl

    * Roderick <hruodr@gmail.com>
    | On Fri, 14 Aug 2026, Ralf Fassel wrote:

    | > NB. All of the discussion in this thread holds for 'if' as well.
    | > You can brace the conditional expression for 'if', or you can double
    | > quote it, with the same consequences as for 'expr'.

    | Look:

    | % set a test
    | test
    | % expr {$a}
    | test
    | % if {$a} {return 1} else {return 0}
    | expected boolean value but got "test"

    To be expected (pun intended :-).

    'expr' is just looking for any expression, but 'if' requires a boolean.

    The equivalent for the 'if' would be

    expr {$a ? 1 : 0}

    which yields the exact same error as 'if', since a boolean value is
    expected at the position of $a.

    R'
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Roderick@hruodr@gmail.com to comp.lang.tcl on Fri Aug 14 13:59:19 2026
    From Newsgroup: comp.lang.tcl



    On Fri, 14 Aug 2026, Ralf Fassel wrote:

    * Roderick <hruodr@gmail.com>
    | On Fri, 14 Aug 2026, Ralf Fassel wrote:

    | > NB. All of the discussion in this thread holds for 'if' as well.
    | > You can brace the conditional expression for 'if', or you can double
    | > quote it, with the same consequences as for 'expr'.

    | Look:

    | % set a test
    | test
    | % expr {$a}
    | test
    | % if {$a} {return 1} else {return 0}
    | expected boolean value but got "test"

    To be expected (pun intended :-).

    'expr' is just looking for any expression, but 'if' requires a boolean.

    The equivalent for the 'if' would be

    expr {$a ? 1 : 0}

    which yields the exact same error as 'if', since a boolean value is
    expected at the position of $a.

    The set of all integers is mapped to booleans, the set of all floating
    point numbers also, but not the set of all strings (but a small
    subset containing yes, no, true, false).
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Robert Heller@heller@deepsoft.com to comp.lang.tcl on Fri Aug 14 15:01:18 2026
    From Newsgroup: comp.lang.tcl

    At Fri, 14 Aug 2026 13:59:19 +0000 Roderick <hruodr@gmail.com> wrote:



    On Fri, 14 Aug 2026, Ralf Fassel wrote:

    * Roderick <hruodr@gmail.com>
    | On Fri, 14 Aug 2026, Ralf Fassel wrote:

    | > NB. All of the discussion in this thread holds for 'if' as well.
    | > You can brace the conditional expression for 'if', or you can double
    | > quote it, with the same consequences as for 'expr'.

    | Look:

    | % set a test
    | test
    | % expr {$a}
    | test
    | % if {$a} {return 1} else {return 0}
    | expected boolean value but got "test"

    To be expected (pun intended :-).

    'expr' is just looking for any expression, but 'if' requires a boolean.

    The equivalent for the 'if' would be

    expr {$a ? 1 : 0}

    which yields the exact same error as 'if', since a boolean value is expected at the position of $a.

    The set of all integers is mapped to booleans, the set of all floating
    point numbers also, but not the set of all strings (but a small
    subset containing yes, no, true, false).
    Yes. The mapping of "numbers" to boolean is a tradional artefact of C that Tcl "inheirited". The mapping of yes, no, true, false as boolean is a "feature" of Tcl, mostly because Tcl can't do this C idiom:
    #define TRUE 1
    #define FALSE 0
    while (TRUE) {
    /* some code */
    }
    But in Tcl you can do
    while {true} {
    # some code
    }
    (and yes the first argument to while is also passed to the innerards of expr, just like for if.)


    --
    Robert Heller -- Cell: 413-658-7953 GV: 978-633-5364
    Deepwoods Software -- Custom Software Services
    http://www.deepsoft.com/ -- Linux Administration Services
    heller@deepsoft.com -- Webhosting Services
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Ralf Fassel@ralfixx@gmx.de to comp.lang.tcl on Fri Aug 14 17:22:05 2026
    From Newsgroup: comp.lang.tcl

    * Roderick <hruodr@gmail.com>
    | The set of all integers is mapped to booleans, the set of all floating
    | point numbers also, but not the set of all strings (but a small
    | subset containing yes, no, true, false).

    Exactly.
    https://www.tcl-lang.org/man/tcl8.6.17/TclLib/GetInt.htm
    states:
    [...]
    Tcl_GetBoolean expects src to specify a boolean value.
    If src is any of 0, false, no, or off, then Tcl_GetBoolean stores a
    zero value at *intPtr.
    If src is any of 1, true, yes, or on, then 1 is stored at *intPtr.
    Any of these values may be abbreviated, and upper-case spellings are
    also acceptable.


    Compare this to perl:
    https://perlmaven.com/boolean-values-in-perl

    What values are true and false in Perl?
    So the following scalar values are considered false:
    undef - the undefined value
    0 the number 0, even if you write it as 000 or 0.0
    '' the empty string.
    '0' the string that contains a single 0 digit.

    All other scalar values, including the following are true:
    1 any non-0 number
    ' ' the string with a space in it
    '00' two or more 0 characters in a string
    "0\n" a 0 followed by a newline
    'true'
    'false' yes, even the string 'false' evaluates to true.

    Especially note that last one :-)

    % perl -e 'if (false) { print "true\n"; }'
    true

    R'
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Roderick@hruodr@gmail.com to comp.lang.tcl on Fri Aug 14 19:53:19 2026
    From Newsgroup: comp.lang.tcl


    On Fri, 14 Aug 2026, Ralf Fassel wrote:

    * Roderick <hruodr@gmail.com>
    | The set of all integers is mapped to booleans, the set of all floating
    | point numbers also, but not the set of all strings (but a small
    | subset containing yes, no, true, false).

    Exactly.
    https://www.tcl-lang.org/man/tcl8.6.17/TclLib/GetInt.htm
    states:
    [...]
    Tcl_GetBoolean expects src to specify a boolean value.
    If src is any of 0, false, no, or off, then Tcl_GetBoolean stores a
    zero value at *intPtr.
    If src is any of 1, true, yes, or on, then 1 is stored at *intPtr.
    Any of these values may be abbreviated, and upper-case spellings are
    also acceptable.

    Look:

    % if {0.1} {return 1} else {return 0}
    1
    % if {-5} {return 1} else {return 0}
    1

    Sure innherited from C, as Robert Heller said, but is this an
    undocumented feature?

    I use it continuously ...

    R.

    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Roderick@hruodr@gmail.com to comp.lang.tcl on Fri Aug 14 20:00:08 2026
    From Newsgroup: comp.lang.tcl


    Well, the man page of if:

    """""
    The if command evaluates expr1 as an expression (in the same way that expr evaluates its argument). The value of the expression must be a boolean (a numeric value, where 0 is false and anything is true, or a string value
    such as true or yes for true and false or no for false); ...
    """""

    https://www.tcl-lang.org/man/tcl9.0/TclCmd/if.html



    On Fri, 14 Aug 2026, Roderick wrote:


    On Fri, 14 Aug 2026, Ralf Fassel wrote:

    * Roderick <hruodr@gmail.com>
    | The set of all integers is mapped to booleans, the set of all floating
    | point numbers also, but not the set of all strings (but a small
    | subset containing yes, no, true, false).

    Exactly.
    https://www.tcl-lang.org/man/tcl8.6.17/TclLib/GetInt.htm
    states:
    [...]
    Tcl_GetBoolean expects src to specify a boolean value.
    If src is any of 0, false, no, or off, then Tcl_GetBoolean stores a
    zero value at *intPtr.
    If src is any of 1, true, yes, or on, then 1 is stored at *intPtr.
    Any of these values may be abbreviated, and upper-case spellings are
    also acceptable.

    Look:

    % if {0.1} {return 1} else {return 0}
    1
    % if {-5} {return 1} else {return 0}
    1

    Sure innherited from C, as Robert Heller said, but is this an
    undocumented feature?

    I use it continuously ...

    R.


    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From Ralf Fassel@ralfixx@gmx.de to comp.lang.tcl on Mon Aug 17 11:27:25 2026
    From Newsgroup: comp.lang.tcl

    * Roderick <hruodr@gmail.com>
    | On Fri, 14 Aug 2026, Ralf Fassel wrote:

    | > * Roderick <hruodr@gmail.com>
    | > | The set of all integers is mapped to booleans, the set of all floating
    | > | point numbers also, but not the set of all strings (but a small
    | > | subset containing yes, no, true, false).
    | >
    | > Exactly.
    | > https://www.tcl-lang.org/man/tcl8.6.17/TclLib/GetInt.htm
    | > states:
    | > [...]
    | > Tcl_GetBoolean expects src to specify a boolean value.
    | > If src is any of 0, false, no, or off, then Tcl_GetBoolean stores a
    | > zero value at *intPtr.
    | > If src is any of 1, true, yes, or on, then 1 is stored at *intPtr.
    | > Any of these values may be abbreviated, and upper-case spellings are
    | > also acceptable.

    | Look:

    | % if {0.1} {return 1} else {return 0}
    | 1
    | % if {-5} {return 1} else {return 0}
    | 1

    | Sure innherited from C, as Robert Heller said, but is this an
    | undocumented feature?

    | I use it continuously ...

    My citation was for the Tcl_GetBoolean() C function, in order to show
    which values (numbers and strings) are accepted as *boolean* values:

    % string is boolean t
    1
    % string is boolean f
    1
    % string is boolean x
    0

    % string is boolean 0
    1
    % string is boolean 1
    1

    % string is boolean 3
    0

    # but of course:
    % if {3} { puts true } { puts false }
    true

    The complete expression parser in addition does the "number magic".

    R'
    --- Synchronet 3.22a-Linux NewsLink 1.2