Overview
| Artifact ID: | 8a12fc8acb8b67cb7bdedc540d8cf57c8cfb1a96 |
|---|---|
| Ticket: | 781929ffffffffffffffffffffffffffffffffff
[lexpand] expand-in-place command |
| User & Date: | muonics on 2003-08-02 11:32:36 |
Changes
- assignee changed to: "msofer"
- cmimetype changed to: "text/plain"
- comment changed to:
This relatively simple patch to Tcl 8.4.4 adds a new "lexpand" command to the core for expanding lists "in place" during evaluation. It is suggested as an alternative to the proposed {} prefix syntax convention described by TIP #144. "lexpand" was chosen instead of "expand" because Unix systems tend to have an "expand" command, which might be more likely to cause silent-but-erroneous behavior runing scripts using the new command in older versions of Tcl (this way it's more likely to give an "unknown command" error than do something incorrect with the arguments). Usage: lexpand ?list ...? The patch adds a new Tcl_Obj type that is just a renamed list object for purposes of flagging the object as requiring expansion. The command takes zero or more arguments and returns a list object consisting of those arguments but with the new object type. TclEvalObjvInternal() is modified to recognize this type and reconstruct the objv array, expanding any elements of the new type into separate arguments before looking up and calling the command. lexpand accepts multiple arguments so that it can be nested for multiple levels of expansion. e.g. command [lexpand [lexpand $args]] It can also be used to execute list variables directly (similar to eval): [expand $script] It cannot, of course, be used with "set" unless the expansion results in a single element result: set x [list a b c d e] set y [expand $x] ...will result in an error because it is equivalent to... set y a b c d e Likewise, you cannot return [expand $list], unless $list matches the allowed options, return codes, etc. for return. In other words, I guess you could say that the new Tcl_Obj type is not a first-class object, which is essentially the intent of expansion in place. One caveat: no assumption is made in this version of the patch as to whether empty list elements should be discarded. That is... [expand $script] ..is not the same as... eval $script ... if $script contains empty strings or lists. e.g. set script [list puts ""] [expand $script] => puts "" eval $script => puts However, it could be with very minor changes (just build the result element-by-element in Tcl_LexpandObjCmd() rather than calling Tcl_NewListObj() with the full set of arguments). Perhaps the behavior could be made an option. But I wasn't certain which behavior people expect/desire. My hope is that this will make the {} syntax unnecessary, but I believe that it would be extremely easy to support both forms if desired or use this code as the basis for {} if (unfortunately) that syntax is chosen over [lexpand]. Oh, and please check to make sure there aren't any reference counting issues! :) - foundin changed to: "None"
- priority changed to: "5 Medium"
- resolution changed to: "None"
- status changed to: "Open"
- submitter changed to: "muonics"
- subsystem changed to: "45. Parsing and Eval"
- title changed to: "[lexpand] expand-in-place command"
- type changed to: "Patch"