Re: (declare (pure ...))

Peter Bex <[email protected]>
Newsgroups gmane.lisp.scheme.chicken
Message-ID <Zcdr6nIwP3aZl1kF@doggett>
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 (application/pgp-signature, 488 B)
-----BEGIN PGP SIGNATURE-----

iQEzBAEBCAAdFiEE6bh5EUSYP1EE+1UTER25+ctFibAFAmXHa+cACgkQER25+ctF
ibBzgAgAxtXYs5winfDvC5aZIK8qJzg5vLEcuInusguekOaGDDBn1yxtNIIxJUSO
s6Tsmkj5+NUdDZ1ag7Ga1DR25f9Vzmiig7kiKe9iI1b6PnF9lWdLFu47e3fsJL7E
Ve3gBgXe9t4bvO+BnTBYKQMwA1XbVhXRbnZR15s/sMGffCIeDi2YpM8To6szIQrm
28g+MsqFqcsdIOsErNqmwmO+cksxR8xhjcdUDeff4x7D/eK39h+NaPp6ivZ1Szco
yyWrAMiIdnvv5Vox3DOnpxvim84zcd3hmnUOF1tFDDX2gyVsgRVmYCwvEJlUQ6JE
aaA1og2fHpodrfTaK65uUBSQ0TTYDw==
=3MHF
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.