[swift-evolution] Proposal proposal: @pure keyword

Dmitri Gribenko gribozavr at gmail.com
Sat Jan 9 04:29:45 CST 2016

On Sat, Jan 9, 2016 at 10:53 AM, Andrew Bennett via swift-evolution <
swift-evolution at swift.org> wrote:

> A function, method or closure is pure if:
>  * all functions, methods and closures it calls are also pure (this
> includes referencing self from a method or property)
>  * it only externally references let variables of pure type, let
> properties on those variables, and methods/computer-properties marked as
> pure.

I'm concerned that with this definition we won't be able to mark many APIs
as pure, even though they actually are pure.  The issue is that this
definition disallows local mutation.  Consider CollectionType.sort() -- the
way it is implemented is that it first copies the collection into an array,
and then sorts that array in-place.  sortInPlace() isn't pure, but because
the mutation happens on local state, the whole operation is pure.


(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160109/1d5ad8f3/attachment.html>

More information about the swift-evolution mailing list