Le 21 déc. 2015 à 12:23, Joe Groff via swift-evolution 
<[email protected]> a écrit :

> Some behaviors like `lazy` and `resettable` want to take control of the 
> storage to manage their semantics, but many behaviors are adapters 
> independent of how the underlying behavior behaves. These kinds of behavior 
> are easy to compose with other behaviors and to override base class 
> properties with. You could use inheritance-like syntax to indicate a 
> "wrapping" behavior like this, and commandeer `super` to refer to the 
> underlying property. For instance, `synchronized`:

It's unclear to me whether you can write behaviour extensions with this new 
model. I'm not sure if that's really needed, but with the struct-based model, 
you could.


> If you want to refer back to the containing `self`, we could support that 
> too, and by treating behavior functions specially we should be able to 
> maintain coherent semantics for backreferencing value types as well. 
> Implementing `synchronized` with a per-object lock could look like this:
> 
> var behavior synchronizedByObject<T>: T where Self: Synchronizable {
>   get {
>     return self.withLock { return super }
>   }
>   set {
>     return self.withLock { return super }
>   }
> }

Instead of simply writing `: T`, you could use a parameter list to give a name 
to that `super`-property:

        var behavior synchronizedByObject<T>(var parentProperty: T) where Self: 
Synchronizable {
          get {
            return self.withLock { return parentProperty }
          }
          set {
            return self.withLock { parentProperty = newValue }
          }
        }



-- 
Michel Fortin
[email protected]
https://michelf.ca

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to