4 ms·
Ask yourself why Lisp has no statements. Is it impossible to issue orders to the Lisp runtime?
by SeanLuke 4y ago
Ask yourself why Lisp has no statements. Is it impossible to issue orders to the Lisp runtime?
- FeepingCreature 4y agoLisp does have statements, such as `setf` or `loop`. Just because you also attach an expression to it because hey, gotta evaluate to something, doesn't mean it's not fundamentally a statement. Sure, syntactically it's an expression-based language, but some of those are expressions in syntax only. If a function terminates in nil, what exactly did it compute? And what exactly is the point of all but the last argument to a `progn`? An expression that is evaluated for the side effects, not the result value, is a statement in every way that matters. (Haskell has a stronger claim because it actually captures the side effects as a value.)
- SeanLuke 4y ago> Lisp does have statements, such as `setf` or `loop`. Just because you also attach an expression to it because hey, gotta evaluate to something, doesn't mean it's not fundamentally a statement. I think the general consensus is that expressions evaluate to values in unexceptional situations, full stop. Whether they have side effects is immaterial. Whether the value returned is useful or not is also immaterial. Perhaps your examples weren't the best, since both setf and loop evaluate to values which are often useful. This isn't just Lisp. For example, the C99 specification explicitly declares that all function calls are expressions, even if they return void. Wikipedia also defines an expression (vs. statement) unambiguously as "a syntactic entity in a programming language that may be evaluated to determine its value.... Expression is often contrasted with statement—a syntactic entity that has no value (an instruction)." https://en.wikipedia.org/wiki/Expression_(computer_science) https://en.wikipedia.org/wiki/Expression_(computer_science)
- FeepingCreature 4y agoI think you're mixing up syntax and semantics. Function calls that return void are usually better classified semantically as procedures, at least when trying to understand how the program is arranged.
- afiori 4y ago> If a function terminates in nil, what exactly did it compute? nil. The fact that you can syntactically put loops and ifs in place of expressions is what makes them expressions
- FeepingCreature 4y agoLotta CPU time spent to get you that nil. One would think you could just `(defun fun () nil)`.
- afiori 4y agoThere seems to be a disagreement about what an expression is. I have the impression that you think that an expression is a way to compute a value, while I would posit that an expressions are a method of combining values. Not really an expression: a0 = 1; a1 = f(2); if (a0 < a1){ a2 = getInput(); } else { a2 = 3; } result = a0 + a1 + a2; More of an expression: result = 1 + f(2) + (a0 < a1 ? getInput() : 3);