jimtcl icon indicating copy to clipboard operation
jimtcl copied to clipboard

Proposal for a new 'leval' command

Open msteveb opened this issue 1 year ago • 2 comments

This is a proposal. Feedback is welcome, including alternative names (such as lsubst). From the docs:

This command is similar to list in that it creates a list, but uses the same rules as scripts when constructing the elements of the list. It is somewhat similar to subst except it produces a list instead of a string.

This means that variables are substituted, commands are evaluated, backslashes are interpreted, the expansion operator is applied and comments are skipped.

Consider the following example.

    set x 1
    set y {2 3}
    set z 3
    leval {
        # This is a list with interpolation
        $x; # The x variable
        {*}$y; # The y variable expanded
        [string cat a b c]; # A command
        {*}[list 4 5]; # A list expanded into multiple elements
        "$z$z"; # A string with interpolation
    }

The result of leval is the following list with 7 elements.

1 2 3 abc 4 5 33

This is particularly useful when constructing a list (or dict) as a data structure as it easily allows for comments and variable and command substitution.

msteveb avatar Jul 24 '24 03:07 msteveb

Nice, though I think lsubst is a far more appropriate name than level, since I can't see how the base operation (substitutions) is related to eval.

gromgit avatar Jul 25 '24 15:07 gromgit

I agree that lsubst is a better name

msteveb avatar Jul 25 '24 23:07 msteveb

I plan to merge this as part of #348

msteveb avatar Jul 08 '25 09:07 msteveb

Merged as part of #348 as lsubst

msteveb avatar Jul 15 '25 23:07 msteveb