0

The code is below. Running separately, the top one does not compile in any way but the bottom segment compiles fine.

proc printbobs  {times {textd "cream corn"}} {
    for {set r 0} {$r<$times} {incr r}{
        puts $textd
    }
    return $times
}
printbobs 2 
proc printText {times2 {textp "hello word"}} {
    for {set i 0} {$i<$times2} {incr i} {
        puts $textp
    }
    return $times2
}
printText 2
Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
mega_creamery
  • 667
  • 7
  • 19

1 Answers1

6

There is a missing space between {incr r} and { in the second line of the procedure.

Peter Lewerin
  • 13,140
  • 1
  • 24
  • 27
  • 1
    @mega_creamery, to make it more understandable, while those curly braces in Tcl *suggest* Tcl uses parsing rules similar to those of C-like programming languages, Tcl's rules are different. In Tcl, matching curly braces delimit "words" -- chunks of text forming arguments to commands. In your first code block -- were it written correctly -- the `for` command would receive 4 arguments: `set r 0`, `$r<$times`, `incr r` and the body. In your case Tcl failed to parse the third argument as it found `{` immediately after `{incr r}`, which is not permitted. – kostix Nov 02 '15 at 09:41
  • @mega_creamery, Please read the [Tcl tutorial](https://tcl.tk/man/tcl8.5/tutorial/tcltutorial.html), especially the sections 5-7 there. – kostix Nov 02 '15 at 09:41
  • @mega_creamery: also see [here](http://stackoverflow.com/questions/33306970/tcl-factorial-calculation-code-extra-characters-after-close-brace/33316865#33316865). – Peter Lewerin Nov 02 '15 at 10:28
  • This has been something of an experiment. The result: a 20+ lines answer with examples gets three upvotes in 1½ weeks, while a one-line answer without examples, otherwise the same, gets six upvotes in three days. Obviously (and considering earlier experiences), a short answer is preferred to a complete one. I'm not being sarcastic here, I'm just trying to understand how to provide the best answer. It's not at all unlike how it was when I was teaching C/C++ a decade ago, actually. – Peter Lewerin Nov 02 '15 at 10:34
  • 1
    My take on this is that those upvoting still feel the need to actually comprehend the answer. Surely, to comprehend a comprehensive answer (pun intended) there is the need for investing more time or effort or both. BTW I've got my own [most-idiotic-and-useless-and-still-the-most-upvoted](http://stackoverflow.com/a/10347287/720999) answer which basically amounts to citing the manual for the person who was too lazy to do that. Well, in my case it's also just seems that the topic is very frequently being searched for :-) – kostix Nov 02 '15 at 12:24
  • @kostix: this might possibly warrant a discussion, but perhaps elsewhere in that case. Thanks for the input; as you say there must be several factors that influence how answer reception differs. In this case, the title is probably a lot more google-friendly than the one I linked to. I haven't actually looked, but it's quite likely that the statistics-friendly SO community has already studied this. – Peter Lewerin Nov 02 '15 at 12:47