Created
December 1, 2022 10:40
-
-
Save qingwei91/4f08b5b3a36b85c44f0e6fefb6c09c5a to your computer and use it in GitHub Desktop.
referential transparent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
A piece of code can be replaced by a variable/function that represent itself, in all cases! | |
*/ | |
val x = 1 + 2 | |
val y = x + x | |
val z = (1 + 2) + (1+2) | |
assert(z == y == (x + x)) | |
var mx = 20 | |
var my = { mx += 1; mx * mx } | |
assert(my != { mx += 1; mx * mx }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment