|
|
|
|
|
by TedDoesntTalk
1420 days ago
|
|
Flow control? Imperative. No flow control? Declarative. What is flow control? Typically if/then/else statements. Importantly, setting a variable with a conditional does not make the language necessarily imperative. I wonder if a language can be Turing-complete without flow control. My guess is no? |
|
> Flow control? Imperative. > No flow control? Declarative.
I think I'd rather say:
Imperative: Tell the system what to do.
Declarative: Tell the system what you would like to be. The system figures out what to do to get there.
You could well have flow control to say things like "if things are like that, I want things to be such", or "here is a loop building up what I would the state of the system to look like", still without telling the system what to do to get to that state.
> I wonder if a language can be Turing-complete without flow control. My guess is no?
Depends on your definition of "flow control". Untyped lambda calculous is effectively entirely just declaration and application of anonymous functions with only one argument, but it's Turing complete.
You can even try it in any language that has lambdas as first class citizens, e.g. here's a factorial function I wrote in Lambda calculous, but implemented in python:
Does it have flow control? Depends. No python flow control is used, but some of those lambdas implement flow control. But they're not any part of the language (Lambda calculous), we just build them.Would I call Lambda calculous declarative? Not at all!