• uplevel and {*}$args -- variable number of args.

    From Robert Heller@21:1/5 to All on Mon Jun 6 14:41:07 2022
    I am strugling with argument lists that contain lists and what happens with uplevel and {*}$args. The lists are getting flattened. How can I preserve
    the sub-lists? There has got to be way of doing this, but I am failing to manage it.

    uplevel #0 $options(-callback) PLANETARY_ORBIT [from arglist -epoch] \
    "[from arglist -position]" "[from arglist -velocity]"

    Then in the callback proc:

    method _clientCallback {cmd epoch args} {
    switch $cmd {
    ...
    PLANETARY_ORBIT {
    $self setposval {*}$args
    }
    ...
    }
    }

    method setposval {pos vel} {
    ..
    }

    The -position and -velocity options in the original arglist are lists of three numbers, that eventually end up at pos and vel in setposval, but setposval is getting 6 arguments instead. Somewhere between uplevel, the args argument to _clientCallback and the use of {*}$args (and yes, this is all happening inside of SNIT types). Oh, I am using Tcl 8.6.11

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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From [email protected]@21:1/5 to All on Mon Jun 6 21:55:32 2022
    I am strugling with argument lists that contain lists and what happens with >uplevel and {*}$args. The lists are getting flattened. How can I preserve >the sub-lists?

    uplevel #0 $options(-callback) PLANETARY_ORBIT [from arglist -epoch] \
    "[from arglist -position]" "[from arglist -velocity]"

    uplevel wants a list of words, try making the command script a list:

    uplevel #0 [list $options(-callback) PLANETARY_ORBIT [from arglist -epoch] \
    [from arglist -position] [from arglist -velocity]]


    Assumes the result of [from] can be interpreted as a list.

    Dave B

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From briang@21:1/5 to Robert Heller on Mon Jun 6 16:39:06 2022
    On Monday, June 6, 2022 at 12:41:17 PM UTC-7, Robert Heller wrote:
    I am strugling with argument lists that contain lists and what happens with uplevel and {*}$args. The lists are getting flattened.

    Just remember that [uplevel] is another form of [eval]. With these commands, the argument list is processed twice, once by the execution of [eval] and again when [eval] executes the requested command. This means that arguments that require proper
    quoting need to be quoted twice. This is, in essence, what happens with Dave's posted solution.

    -Brian

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mole Cool@21:1/5 to All on Tue Jun 7 01:55:36 2022
    Just use eval, if you start quoting it may get ugly :-)

    uplevel #0 $options(-callback) PLANETARY_ORBIT [from arglist -epoch] \
    [list [from arglist -position] ] [list [from arglist -velocity]]

    Then in the callback proc:

    method _clientCallback {cmd epoch args} {
    switch $cmd {
    ...
    PLANETARY_ORBIT {
    eval $self setposval $args
    }
    ...
    }
    }

    method setposval {pos vel} {
    ..
    }

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From luocl@21:1/5 to Mole Cool on Tue Jun 7 17:49:58 2022
    On 6/7/22 4:55 PM, Mole Cool wrote:
    Just use eval, if you start quoting it may get ugly :-)

    uplevel #0 $options(-callback) PLANETARY_ORBIT [from arglist -epoch] \
    [list [from arglist -position] ] [list [from arglist -velocity]]
    or this style

    uplevel #0 [list $options(-callback) PLANETARY_ORBIT \
    [from arglist -epoch] [from arglist -position] [from arglist -velocity]]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)