×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*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.

# TCl numeric list2

## TCl numeric list

(OP)
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

Hi

#### 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
}
}

Feherke.

### RE: TCl numeric list

consider this:

#### CODE

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

_________________
Bob Rashkin

### RE: TCl numeric list

(OP)
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

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

### RE: TCl numeric list

Hi

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
}

Feherke.

#### 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.

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:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!