Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

whats the difference between a command and a statement

Often when reading about Tcl (e.g. http://antirez.com/articoli/tclmisunderstood.html) you read that "everything is a command". Sometimes you also hear how other languages are, like Tcl, "command languages."

To me with my background in other languages, I just view these "commands" as statements. What precisely is the difference between a command and a statement?

like image 438
Dexygen Avatar asked Sep 25 '09 16:09

Dexygen


1 Answers

Traditionally, in Tcl, the phrase "everything is a command" means that there's no such thing as a "reserved word" command, or one that is defined by the system that you can't change. Every single executable piece of Tcl code is of the format:

command ?arg1? ... ?argN?

There's no such thing as a command that's part of the syntax and can't be overwritten (like "if" and other control structures in most languages). It's entirely possible to redefine the "if" command to do something slightly different.

For example, you could redefine "while" as:

proc while {expression body} {
    for {} {[uplevel 1 expr $expression]} {} {
        uplevel 1 $body
    }
}

The above code being untested... but it shows the general idea.

like image 131
RHSeeger Avatar answered Sep 23 '22 10:09

RHSeeger