[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: (declare (pure ...))
From: |
Peter Bex |
Subject: |
Re: (declare (pure ...)) |
Date: |
Sat, 10 Feb 2024 13:28:26 +0100 |
On Sat, Feb 10, 2024 at 11:12:04AM +0000, siiky via wrote:
> Hi Al,
>
> > On a practical level, I would be sad if vector-ref, for example, was
> > "impure", and thus compiling a vector-ref invalidated all previously-
> > checked globals for the current scope. Likewise, I would prefer to
> > declare a procedure using vector-ref as pure, to let csc know that it
> > does not modify globals (or the filesystem etc).
>
> The function vector-ref doesn't stop being pure (i.e. referentially
> transparent) depending how you use it. The function is always referentially
> transparent -- the expression (vector-ref some-global-vec) isn't. Quoting
> from "Functional Programming in C++" by Ivan Čukić:
CHICKEN's type system differentiates between "pure" and "clean". A "pure"
function has no side effects and will always return the same value given
the same input (excluding the environment).
A "clean" function does not modify any state, but may return different
values at different times depending on the value.
That's why vector-ref is marked as "clean" and not "pure" in types.db.
A procedure like "not" and all type predicates are marked as "pure".
Hope this clears things up a bit!
Cheers,
Peter
signature.asc
Description: PGP signature
- Re: (declare (pure ...)), (continued)
- Re: (declare (pure ...)), Al, 2024/02/10
- Re: (declare (pure ...)), Pietro Cerutti, 2024/02/10
- Re: (declare (pure ...)), Al, 2024/02/10
- Re: (declare (pure ...)), Pietro Cerutti, 2024/02/10
- Re: (declare (pure ...)), Al, 2024/02/10
- Re: (declare (pure ...)), Pietro Cerutti, 2024/02/10
- Re: (declare (pure ...)), Pietro Cerutti, 2024/02/10
- Re: (declare (pure ...)), Peter Bex, 2024/02/10
- Re: (declare (pure ...)), Pietro Cerutti, 2024/02/10
- Re: (declare (pure ...)), siiky, 2024/02/10
- Re: (declare (pure ...)),
Peter Bex <=
- Re: (declare (pure ...)), Al, 2024/02/10
Re: (declare (pure ...)), Pietro Cerutti, 2024/02/10