3 ms·
This example of "everything as an expression" doesn't take it as far as Tcl, though. In the above code snippet, the conditional body is surrounded by braces, wh
by mroll 10y ago
This example of "everything as an expression" doesn't take it as far as Tcl, though. In the above code snippet, the conditional body is surrounded by braces, which are syntax. In Tcl, the second argument to the 'if' command is also an expression, which only uses braces as a quoting mechanism, if it needs to.
- wtetzner 10y agoI'm not sure I understand why it matters if the syntax requires braces or not. The things inside the braces are still expressions.
- mroll 10y agoIt matters because if the braces are not syntax, you can decide what code to execute as the condition body at runtime. set condition-body {puts "Hello, world"} if { $condition } $condition-body To get this to run, you need to splice in the condition-body like so, if { $condition } {*}$condition-body But you get the point.
- wtetzner 10y agoBut the "then" and "else" parts of the Rust "if" are expressions. What you're talking about doesn't seem to be related to which things are expressions, it's more like being able to eval code at runtime.