Forum OpenACS Development: set variable into an array

Collapse
Posted by Denis Barut on
Hi,

I try to set an array with variable, but it always take the name of it, not the value !
the answer is maybe obvious, but i've really no glue on array stuff

($user_id $package_id)

array set ref {value {$user_id $package_id} html {size 20}}

...

set categories [template::widget::category ref {mode edit} ]

I try a lot of different way but without succes

Any help is welcome !

Denis
Collapse
Posted by Michael Hinds on
Tcl doesn't perform substitution inside curlies (so your $ or [ ] won't work). I think you're looking for this:
array set ref [list value "$user_id $package_id" html {size 20}]
Hope you have a better glue now :)
Collapse
Posted by Tilmann Singer on
This is normal tcl behaviour: stuff inside curly brackets will not be processed. Unless it is a code block that is being passed again to the interpreter explicitely, like in if { ... } { ... }.

To construct the list you want with substituted variable values, you can do something like that:

array set ref [list [list $user_id $package_id] html [list size 20]]

Collapse
Posted by Denis Barut on
Thanks a lot for the fast glue 😉
Collapse
Posted by Jonathan Ellis on
actually, things like if aren't even special cases; the code in brackets is passed to the if proc as a single arg like any other use of brackets as grouping.  The if then evaluates it in the parent context so it sort of LOOKS like it got evaluated before the if but really it didn't.  Otherwise, things like

if $a {
    set b [foo]
}

would have very surprising results if foo happened to have some global side effects that you didn't always want to see!