Re: Some non-obvious Swift goodies
Re: Some non-obvious Swift goodies
- Subject: Re: Some non-obvious Swift goodies
- From: Chris Hanson <email@hidden>
- Date: Thu, 05 Jun 2014 20:59:46 -0700
On Jun 5, 2014, at 2:52 PM, Scott Ribe <email@hidden> wrote:
>
>> On Jun 5, 2014, at 3:00 PM, Jens Alfke <email@hidden> wrote:
>>
>> Deferred evaluation does look extremely powerful, but I can imagine it’s also potentially very dangerous if misused, in that it can make the semantics of the calling code very non-obvious.
>
> Yes. Note that the feature comes from functional languages, where it does NOT have the problems you brought up, because the deferred functions do not have side effects.
The C preprocessor in some ways gives a form of deferred evaluation, in that the arguments to macros are substituted into the macro as-is rather than evaluated and the result substituted. This is actually a common source of bugs for macro authors, as one must write a macro carefully to control the evaluation such that it only happens once to avoid side effects.
Swift's @auto_closure attribute can be used for something like this in a much more controlled fashion, since the closure itself can be passed around without evaluation.
-- Chris
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden