tclwannabe
Programmer
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.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
In which way ?tclwannabe said:compare two numeric lists
[b]proc[/b] lcmp [teal]{[/teal]a b[teal]}[/teal] [teal]\[/teal]
[teal]{[/teal]
[b]set[/b] diff [teal][[/teal][b]expr[/b] [teal][[/teal][b]llength[/b] [navy]$a[/navy][teal]]-[[/teal][b]llength[/b] [navy]$b[/navy][teal]]][/teal]
[b]if[/b] [teal]{[/teal][navy]$diff[/navy][teal]==[/teal][purple]0[/purple][teal]}[/teal] [teal]{[/teal]
[b]return[/b] [purple]0[/purple]
[teal]}[/teal] [b]elseif[/b] [teal]{[/teal][navy]$diff[/navy][teal]<[/teal][purple]0[/purple][teal]}[/teal] [teal]{[/teal]
[b]return[/b] [purple]1[/purple]
[teal]}[/teal] [b]else[/b] [teal]{[/teal]
[b]return[/b] [teal]-[/teal][purple]1[/purple]
[teal]}[/teal]
[teal]}[/teal]
[b]proc[/b] lcompare [teal]{[/teal]a b c d[teal]}[/teal] [teal]\[/teal]
[teal]{[/teal]
[b]foreach[/b] x [navy]$a[/navy] y [navy]$b[/navy] [teal]{[/teal] [b]if[/b] [teal]{[/teal][navy]$x[/navy][teal]!=[/teal][navy]$y[/navy][teal]}[/teal] [teal]{[/teal] [b]return[/b] [purple]0[/purple] [teal]}[/teal] [teal]}[/teal]
[b]foreach[/b] x [navy]$c[/navy] y [navy]$d[/navy] [teal]{[/teal] [b]if[/b] [teal]{[/teal][navy]$x[/navy][teal]!=[/teal][navy]$y[/navy][teal]}[/teal] [teal]{[/teal] [b]return[/b] [purple]0[/purple] [teal]}[/teal] [teal]}[/teal]
[b]return[/b] [purple]1[/purple]
[teal]}[/teal]