|
|
|
|
|
by jeffdavis
4901 days ago
|
|
(please excuse my poor knowledge of lisp... check out the wikipedia page if my explanation falls apart: http://en.wikipedia.org/wiki/Referential_transparency_%28com...) My clojure interpreter gives "10" not "20". The function "or" is referentially transparent, because if you call it with the same argument values you are going to get the same result every time. (or 10 20) is the same as 10. However, the following function is not referentially transparent: (defn incx [] (do (def x (+ x 1)) x))
Because subsequent calls return different results: (def x 2)
(incx)
(incx)
Things like side effects and many kinds of metaprogramming break referential transparency. |
|
That said, if any admission of mutability is sufficient to disqualify a language from claiming to encourage or support referential transparency, then Haskell fails the test, too. unsafePerformIO is a trivial example. I'm sure if you were determined to introduce nondeterminism, you could find a lot more. But that's not the point, is it?
Maybe there's a way to demonstrate your point, but what you've shown here doesn't involve homoiconicity or macros at all.