Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


TCl numeric list

TCl numeric list

TCl numeric list

I need help with writing a procedure to compare two numeric lists in tcl. I am new to the language and therefore I just need some guidance.

RE: TCl numeric list


Quote (tclwannabe):

compare two numeric lists
In which way ?

For example this procedure compares two lists and returns -1, 1 or 0 when the first list is longer, the second list is longer or their lengths are equal respectively :

CODE --> Tcl

proc lcmp {a b} \
  set diff [expr [llength $a]-[llength $b]]

  if {$diff==0} {
    return 0
  } elseif {$diff<0} {
    return 1
  } else {
    return -1


RE: TCl numeric list

consider this:


% set a {1 2 3}
1 2 3
% set b {4 5 6}
4 5 6
% foreach x $a y $b {puts $x,$y}

Bob Rashkin

RE: TCl numeric list

thanks for your help both of you. The thing I am trying to do is to compare two numeric lists and then another set of two lists and if they both are equal then I do the next action. I understand the solution you have shared with me but the problem is with writing a procedure that will take four lists compare a particular set of two and then give me a result.

RE: TCl numeric list

basically for equality elements of the lists have to be same.  

RE: TCl numeric list


Not sure what "particular set of two" should be, this procedure takes 4 parameters then compares 1st with 2nd and 3rd with 4th. It returns true if the compared lists contain the same elements in the same order.

CODE --> Tcl

proc lcompare {a b c d} \
  foreach x $a y $b { if {$x!=$y} { return 0 } }
  foreach x $c y $d { if {$x!=$y} { return 0 } }
  return 1


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close