|
From: | Al |
Subject: | Re: (declare (pure ...)) |
Date: | Sat, 10 Feb 2024 12:10:00 +0200 |
User-agent: | Betterbird (Linux) |
On 2024-02-10 11:53, Pietro Cerutti wrote:
I don't see why vector-ref would be any less pure than, say, a let binding. Or do you mean vector-set! ?vector-ref, applied to a global, could return different values even when called with the same arguments. Between calls, some other code could modify the contents of the vector. So according to referential transparency, vector-ref could not be pure. Likewise a function that calls vector-ref could not be pure.
Further, according to referential transparency no procedure that *reads* a global (not just vectors -- even imediate values like numbers, booleans) can be pure. It might return different values if impure code modifies the global between calls to the procedure in question.
In contrast, a let binding can only be modified by the code in the current scope.
There should still be a way to communicate to the optimizer that vector-ref, or some procedure that uses vector-ref on a global identifier (but does not call set! / vector-set! on globals) does not, uh, modify any globals.
-- Al
[Prev in Thread] | Current Thread | [Next in Thread] |