Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Python, Lua and Tcl - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Java, C, C++, Ruby, MySQL and Linux / Tomcat systems
using list variables in commands

Posted by TimT (TimT), 26 October 2005
Using tcl/tk on Linux (mandrake9.2)
I am trying to generate a list that holds the parameter to draw an image
it is made up of a list of coordinates to draw a polygon
and a pair of values used to move the drawing
(later I want to add a colour value)
so at this stage the list should hold 2 variable
- the coordinates and move coordinate

the code I have used is

 set lns {9 1  14 6  14 8  9 8  9 12  5 12  5 8  0 8  0 6  5 1}
 set pos {20 3}
 set diag "$lns"  ; lappend diag "$pos"
 set col "gold"

if I then use:
 .panl create polygon $lns -fill $col -tags za
 .panl move za 20 3
it works fine

if I use:
 .panl create polygon $lns -fill $col -tags za
 .panl move za $pos
it comes back with an error message for $pos
--- wrong args
ie expect 2 values for $pos?

if I use:
 .panl create polygon [lindex $diag 0] -fill $col -tags za
 .panl move za 20 3
I get an error message for lindex
--wrong coordinates expected even number got 1

why does it work for the first one and not the others?

Posted by admin (Graham Ellis), 27 October 2005
I think this is what I call the "Anne Marie" problem.  I used to work with a young lady who insisted that her name was Anne Marie, two words, not joined together or hypenated.  So - one person but two names.  She was (naturally) entitled to call herself whatever she liked, but in a list of names it always looked odd ....

Meeting:  Peter Steve David Anne Marie Graham

looks like 6 people but was really 5

In the second piece of code, you've got an "Anne Marie" - a list of deferred block that's a single, two-word parameter rather than two parameters; that's what's causing your problem there.

Can't spot the issue with the third piece of code; looks very curious as the lindex call looks right and I suspect that you're seeing an artefact of a problem elsewhere.  Is the lindex that you've shown the source code for the one with the error ... can you check the line number at which the error occurs.  I think you might find it's not actually in the code quoted  

Posted by TimT (TimT), 27 October 2005
I thought it was something like that but couldn't get through to what I wanted to do.
I have worked out what is happening but it still leaves a question as to why it is different for the  'move tagname' command

 set lns {9 1  14 6  14 8  9 8  9 12  5 12  5 8  0 8  0 6  5 1}
 set pos {20 3}
 set diag1 $lns  ; lappend diag1 "$pos"
 set diag "" ; lappend diag $lns  ; lappend diag "$pos"

diag1 stores as:
9 1 14 6 14 8 9 8 9 12 5 12 5 8 0 8 0 6 5 1 {20 3}
diag stores as:
{9 1  14 6  14 8  9 8  9 12  5 12  5 8  0 8  0 6  5 1}  {20 3}

 .panl create polygon [lindex $diag1 0] -fill $col -tags za
is an error because [lindex $diag1 0] is a single digit (9) where it should be a string of coordinates (ie at least 2 pairs)

 .panl create polygon [lindex $diag 0] -fill $col -tags za
works correctly as it sees a string of character, it even keeps the spacing that I added to be able to see the coordinate pairs

 .panl move za $pos
 .panl move za [lindex $diag 1]
don't work they only see a single entity where there should be a pair of numbers

A workaround :
 set rel [lindex $diag 1]
 .panl move za [lindex $rel 0] [lindex $rel 1]

so it seems that the 'create polygon' command accepts the list entity as a string
but the 'move tagname' command accepts the list entity as an entity still
Any comments?

This page is a thread posted to the opentalk forum at and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2018: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01225 708225 • FAX: 01225 793803 • EMAIL: • WEB: • SKYPE: wellho