[swift-evolution] Proposal proposal: @pure keyword
Matthew Johnson
matthew at anandabits.com
Sat Jan 9 08:20:57 CST 2016
> On Jan 9, 2016, at 4:29 AM, Dmitri Gribenko via swift-evolution <swift-evolution at swift.org> wrote:
>
> On Sat, Jan 9, 2016 at 10:53 AM, Andrew Bennett via swift-evolution <swift-evolution at swift.org <mailto: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.
The way I ready it is "it only externally references let variables of pure type, let properties on those variables, and methods/computer-properties marked as pure.
Externally is the key word here, which would allow for internal / local mutation. Note: properties of self would be an external reference.
>
> Dmitri
>
> --
> main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
> (j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com <mailto:gribozavr at gmail.com>>*/
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160109/b602453f/attachment.html>
More information about the swift-evolution
mailing list