# Why in Declarative Programming variables are not reassigned?

I've read that a Declarative language is called "stateless". This means that we can imagine that internally every variable is a constant variable, and it never get reassigned ( in contrast with what usually happens in procedural programming). How can this work?

• Is it clear what you are asking? Can you elaborate a bit on why you think no reassignment might not work? Feb 25 '19 at 23:43
• In mathematics, we can plot f(x) = x*x+4 where x ranges from 0 to 10. We call x a variable, even if we don't alter its value in the definition of f(x). I think that if you read some tutorial for any functional programming language, you will understand the general idea: functions work as in maths.
– chi
Feb 27 '19 at 13:09

This isn't as exotic as it sounds, and you can do it in a procedural language fairly easily. The basic idea is just that instead of changing a value you just have a function return a new value. For instance, instead of something like

string read()
{
string s = '';

while((string c = getchar()) != '\n')
{
s += c;
}

return s;
}


you could write something like

string read()
{
string c = getchar();

if(c == '\n')
{
return '';
}
else
{