stringtclputs

Comma separated coordinates printing in Tcl using puts


How to print a triangle coordinates (1,2) (3,4) (5,6) using puts? I am getting errors for the quotes. puts "triangle just added is" "( " $ax "," $ay ") " "( " $bx "," $by ") " "( " $cx "," $cy ") "


Solution

  • puts takes one argument (A string to write to standard output) or two (A channel to write to and the string). Well, and the optional -nonewline option, so really 2 or 3 arguments. You're giving it a lot more than that, hence errors.

    Like many scripting languages, tcl will expand variables inside double-quoted strings:

    puts "triangle just added is ($ax,$ay) ($bx,$by) ($cx,$cy)"