Hacker News new | ask | show | jobs
by greenpeas 1093 days ago

  #!/usr/bin/env tclsh
  
  puts $argv
I kinda wanted to stop reading after this example. It feels dishonest to start with an example for which there is a builtin. Why didn't you show instead how to output arguments joined by a comma or some other separator instead of space. If I were to update the Go or Python examples to use another separator, it'd be just a 1-2 character change, whereas for Tcl I have no idea how that would look.
3 comments

> Why didn't you show instead how to output arguments joined by a comma or some other separator instead of space.

The Tcl variant to output "comma" as separator (note -- this is not "CSV").

     puts [join $argv ,]
If you wanted "comma space" you'd do:

     puts [join $argv ", "]
If you actually wanted "CSV" then it would be (assuming tcllib is installed):

     package require csv
     puts [csv::join $argv]
Funnily neither version gives the correct result when you have arguments with spaces, e.g. for "-v 5" -d , the tcl one will print {-v 5} -d as a consequence of how tcl represents lists.
The author should have done:

     puts [join $argv]
to avoid that little issue. Doing "puts $argv" triggers Tcl's output of "lists" in a special format that allows the list to be parsed from the text again at a later time.
The author is following examples given in a book, however.
Oh, I missed that. I guess it's alright then. I thought they chose this particular example to "showcase" Tcl by comparison.