Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

TCL Proc to add trailing zero's

proc or lappend/ string map ?

set max 14
set min 4

Add trailing zero’s considering min i.e. 4th position as 1 followed by adding zero’s till we reach (max-1)
Example in above case would be {1 0 0 0 0 0 0 0 0 0}

puts $result
{1 0 0 0 0 0 0 0 0 0}

Let’s say my min changes since its dynamic as it is a procedural argument.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

set min 6

so my output should be

puts $results
{1 0 0 0 0 0 0 0}

Basically output always is calculated from 0 to 13 and whatever is my min we start from there and add 1 in its place and then add trailing zeros to (14-1)**

>Solution :

If I’m reading your examples correctly, this should work:

proc makelist {min max} {
    concat 1 [lrepeat [expr {$max - $min - 1}] 0]
}

puts "{[makelist 4 14]}"
puts "{[makelist 6 14]}"

prints out

{1 0 0 0 0 0 0 0 0 0}
{1 0 0 0 0 0 0 0}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading