[swift-evolution] [Review] SE-0030 Property Behaviors

Maximilian H├╝nenberger m.huenenberger at me.com
Fri Feb 19 10:17:22 CST 2016

First a general question: Are these behaviors also allowed on normal variables in function bodies (regarding the current proposal)?


The "initialValue" should be exposed as closure/function since it can introduce side effects:

        var [resettable] y = functionWithSideEffects()

According to your proposal: "If the behavior includes an initial value requirement declaration, then the identifier initialValue is bound as a get-only computed property that evaluates the initial value expression for the property"

So if I understand it right if I reset "y" "functionWithSideEffects" gets executed.


Can you explain what is the difference between "Self" and "Value" in the following example?:

protocol Fungible {
        typealias Fungus
        func funge() -> Fungus

var behavior runcible<Value where Self: Fungible, Self.Fungus == Value>: Value {
        get {
                return self.funge()

Isn't "Self" the same as "Value"? So it can be rewritten to:

var behavior runcible<Value: Fungible, Value.Fungus == Value>: Value {
        get {
                return self.funge()


You've wrote that behaviors shouldn't be types/type-like e.g. "var x: lazy<Int>".
Can you mention some disadvantages?

I can't see huge ones. However I don't see any advantages.

Is there any advantage regarding a type-like behavior?


I just remembered recursive value types...
We can even eliminate another keyword: "indirect"


var behavior indirect<Value>: Value {
        class Ref<T> {
                var value: T
                init(_ value: T) { self.value = value }

        var reference: Ref<Value> = Ref(initialValue())
        get { return reference.value }
        set { reference.value = newValue }

I'm glad you made it so far :)
- Maximilian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160219/76a43776/attachment.html>

More information about the swift-evolution mailing list