|
|
|
|
|
by groovy2shoes
5258 days ago
|
|
Shows how long it's been since I last used Tcl! Still, Tcl's anonymous functions aren't quite what many people consider to be lambdas: % set inc {x {expr $x + 1}}
% apply $inc 1
2
% apply $inc 1
2
% $inc 1
invalid command name "x {expr $x + 1}"
% inc 1
1
This works fine with `apply`, but if you treat it like a normal function, it does some strange things. Conversely, functions that are defined with `proc` aren't compatible with `apply` unless you wrap them up.I'm not saying it's inadequate, just that the anonymous functions don't quite work how you expect lambdas to work. |
|
One thing to note though, your final [inc 1] has nothing to do w/ $inc. In the interactive REPL (which I'm assuming you used), Tcl will (by default) essentially autocomplete commands if it can, and [inc] completed to [incr], which is "increment". [incr] adds (by default) 1 to the named variable and returns its result. In this case, the variable name happens to be "1", later accessible via "$1", or [set 1], for example.
[edit: I erroneously initially described the "1" in [incr 1] as the integer constant 1; @groovy2shoes reply below reflects my original error. This does go to show another neat feature of Tcl: no keywords.]