3 ms·
Tcl forces you to create new data, because you have to think and work harder to introduce effects on variables in upper scope through the use of uplevel and upv
by thesz 5y ago
Tcl forces you to create new data, because you have to think and work harder to introduce effects on variables in upper scope through the use of uplevel and upvar. This reduces side effects significantly and makes data transformation explicit. Which, in turn, reduces cognitive load and increase productivity.
Tcl also does not have distinguished NULL value like Python, C, C++, C# and many other languages. You do not have to account for that.
The reduction of side effects and no universal no-value value puts Tcl in my hierarchy of programming languages right below Haskell and above pretty much everything else. Tcl is very easy to use when you know how to structure the program.
I still use it for various prototyping when I do not want strict type discipline.
- zelphirkalt 5y agoDoes this non-existence of a no-value not only mean, that when there is no result value, another value (like false or empty string or empty list or whatever) will be used to express that fact, or that an exception is used? One would have to check for those in some cases as well. Those might not be always good alternatives reducing required checks. How does it work?
- auxym 5y agoOne fundamental principle in tcl is that everything is a string (EIAS) [1]. Therefore, an empty string "" is the same thing as a "null value" or 0-length list, but generally doesn't require any special treatment (your function that takes a list as input generally should know how to handle empty lists). [1] In practice things are typed in the interpreter internals for performance reasons, but the language behaves as if EIAS.
- thesz 5y agoLet me offer you an example: proc maybe {onno onjust val} { if {[llength $val] == 2 && [string equal [lindex $val 0] Just]} { lappend onjust [lrange $val 1 end] return [uplevel $onjust] } # I cannot extract value return [uplevel $onno] } maybe {puts "---"} {puts } {Just "huh?"} maybe {puts "---"} {puts } {} This is an example of custom control statement, modeled after Haskell's maybe [1]. [1] https://hackage.haskell.org/package/base-4.16.1.0/docs/Data-Maybe.html#v:maybe https://hackage.haskell.org/package/base-4.16.1.0/docs/Data-... It is easy to use and write. You can follow algebraic data types convention and prefix values with tags and use something like control structure drafted above. I did that, it is relatively comfortable. Note that special case of empty list also handled as if it is Nothing. So it is more useful than would appear. ;)