chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: (declare (pure ...))


From: Pietro Cerutti
Subject: Re: (declare (pure ...))
Date: Sat, 10 Feb 2024 08:13:24 +0000


On 10 Feb 2024, at 09:06, Al <frm.ml@mailgw.com> wrote:


* only side-effect free, or ...

* also return the same value when called with the same arguments?

The first implies the second: to be able to choose from a set of return values for the same given argument, you do need to have side-effects, e.g., interact with a RNG which maintains state, read from a file, maintain an index into a circular vector of results, etc..

Here's what the docs say:
http://wiki.call-cc.org/man/5/Declarations#pure

"referentially transparent, that is, as not having any side effects". You can read "the environment" (including all globals) without actually modifying the environment. Between two applications of the procedure, other impure procedures may modify the environment. So it's not clear if it means Haskell monad purity or immutable purity, hence my question.

I don't get your question: those two things are the same thing :)

Referential transparency means you can substitute an _expression_ with its expansion down to a value. If anything happening in between causes (observable *) changes, you can't do it anymore.

(*) modifying the program counter is not an observable change, for example.


-- 
Pietro Cerutti
I've pledged to give 10% of income to effective charities and invite you to join me.
https://givingwhatwecan.org

Sent from a small device - please excuse brevity and typos.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]