From: jerib on
Very new to tcl and am trying to create a list in the following
manner. Don't know if it is correct. I thought you just did a set and
then you could lappend to it to add further elements.


if {![info exists somevar]} {
set listvar $somevar
} else {
lappend listvar $somevar
}

this is inside a looping program and when it returns it gets back into
the no info exists side. Vars are global . I am probably not using
list correctly. When I output it it returns only one value

puts {$listvar}

Any help would be appreciated. Thanks.
From: bs on
On Jan 12, 6:20 pm, je...(a)mtco.com wrote:
> Very new to tcl and am trying to create a list in the following
> manner. Don't know if it is correct. I thought you just did a set and
> then you could lappend to it to add further elements.
>
> if {![info exists somevar]} {
>     set listvar $somevar} else {
>
>     lappend listvar $somevar
>
> }
>

I think you want to test for the existence of listvar, not somevar,
correct?

> this is inside a looping program and when it returns it gets back into
> the  no info exists side. Vars are global . I am probably not using
> list correctly. When I output it it returns only one value
>
> puts {$listvar}

The braces ({}) will prevent substitution, so you won't get what you
are probably expecting. Instead, do this:

puts $listvar

HTH,
--brett

From: Gerald W. Lester on
jerib(a)mtco.com wrote:
> Very new to tcl and am trying to create a list in the following
> manner. Don't know if it is correct. I thought you just did a set and
> then you could lappend to it to add further elements.
>
>
> if {![info exists somevar]} {
> set listvar $somevar
> } else {
> lappend listvar $somevar
> }

I would think you meant listvar in the info exist.

However, it is not needed as lappend (and append) are documented and defined
to create the variable if it does not exists. Thus you could just do:
lappend listvar $somevar

>
> this is inside a looping program and when it returns it gets back into
> the no info exists side. Vars are global .

Could you post the code where you thought you specified/made them global?


> I am probably not using
> list correctly. When I output it it returns only one value
>
> puts {$listvar}

Curly braces prevent substitutions -- you neither need nor want them here.

>
> Any help would be appreciated. Thanks.


--
+------------------------------------------------------------------------+
| Gerald W. Lester |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+
From: shags72 on
On Jan 12, 11:36 pm, "Gerald W. Lester" <Gerald.Les...(a)cox.net> wrote:
> je...(a)mtco.com wrote:
> > Very new to tcl and am trying to create a list in the following
> > manner. Don't know if it is correct. I thought you just did a set and
> > then you could lappend to it to add further elements.
>
> > if {![info exists somevar]} {
> >     set listvar $somevar
> > } else {
> >     lappend listvar $somevar
> > }
>
> I would think you meant listvar in the info exist.
>
> However, it is not needed as lappend (and append) are documented and defined
> to create the variable if it does not exists.  Thus you could just do:
>         lappend listvar $somevar
>
>
>
> > this is inside a looping program and when it returns it gets back into
> > the  no info exists side. Vars are global .
>
> Could you post the code where you thought you specified/made them global?
>
> > I am probably not using
> > list correctly. When I output it it returns only one value
>
> > puts {$listvar}
>
> Curly braces prevent substitutions -- you neither need nor want them here..
>
>
>
> > Any help would be appreciated. Thanks.
>
> --
> +------------------------------------------------------------------------+
> | Gerald W. Lester                                                       |
> |"The man who fights for his ideals is the man who is alive." - Cervantes|
> +------------------------------------------------------------------------+

The real problem was a mistake in a varname. I have a problem with
dyslexia and it got me on this one.
Yes I should be checking listvar, my typing mistake.
I am going to simplify with lappend instead of set whether it is the
first occurrence or not.
I was debugging when I put the curlies on and Thank you for pointing
that out as a mistake.
This is an embedded version of tcl.
Here is the code anyway. This is very simple I know compared to what I
have seen out there on the web.

global mom_broken_tool_chk
global mom_tool_number
global check_tool_list

if {[info exists mom_broken_tool_chk] && $mom_broken_tool_chk == "ON"}
{
MOM_output_literal " info exists broken tool check list
inside atc 2"
if {![info exists check_tool_list]} {
MOM_output_literal " info exists tool check list inside atc
2"
set check_tool_list $mom_tool_number
MOM_output_literal "
cat_check_tool_list == {$check_tool_list}" ;# this is a mistake I
know
} else {
MOM_output_literal " else tool check list inside atc 2"
lappend check_tool_list $mom_tool_number
}
}

I went to this now.

if {[info exists mom_broken_tool_chk] && $mom_broken_tool_chk == "ON"}
{
lappend cat_check_tool_list $mom_tool_number
}

Thank you both for your help. This is my first computer language and
it is a learning experience.
From: Alexandre Ferrieux on
On Jan 13, 2:37 pm, shags72 <je...(a)mtco.com> wrote:
>
> Thank you both for your help. This is my first computer language and
> it is a learning experience.

Thanks for mentioning this. It is very refreshing to see, for old-
timers like me, that our beautiful language can be the first that
people learn.

Whoever advised you is a wise person. Many thanks to him/her.

-Alex