Вопрос

I've ready somewhere, although I could not find it after much searching, that if some guy where to create a new programming language, it would be completely referentially transparent where everything is an expression.

Some questions about referential transparency indicate that certain languages such as Ruby and Perl have almost everything as an expression.

Is this possible/does it exist?

If I understand it, then if a programming language is completely referentially transparent doesn't this mean there would be no side effects at all, and is it possible to have a complete programming language without side effects?

And the main question of the title, if the goal where to create a completely referentially transparent programming language, would it go without saying that everything would be an expression?

Это было полезно?

Решение

If by expression we understand anything that returns a value, a computation that is not an expression must not return value, and by referential transparency can be safely removed. So yes, referential transparency requires that everything is an expression.

But, everything being an expression does not imply that there can be no side effects. For example in the C language there are many expressions that have side effects: take any expression involving the increment and decrement operators ++ and --.

There are a few programming languages with no side effects. Haskell is the most widely used. It uses a clever trick called monads to resolve situations that require modification of state. For example, to print "Hello" on the screen, Haskell doesn't modify the existing universe into one where the word appears on the screen; it creates and returns a new universe where the word is on the screen.

Другие советы

It is possible to have a complete programming language without side effects. Take a look at lisp, haskell or many other functional languages. I believe these are all pretty good examples of what you are thinking of.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top