<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><span></span></div><div>First a general question: Are these behaviors also allowed on normal variables in function bodies (regarding the current proposal)?</div><div><br></div><div>----------</div><div><br></div><div>The "<b>initialValue</b>" should be exposed as closure/function since it can introduce side effects:</div><div><br></div><div><span style="background-color: rgba(255, 255, 255, 0);"> var [resettable] y = functionWithSideEffects()</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">According to your proposal: "If the behavior includes an <em style="box-sizing: border-box;">initial value requirement declaration</em>, then the identifier <code style="box-sizing: border-box; padding: 0.2em 0px; margin: 0px; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;">initialValue</code> is bound as a get-only computed property that evaluates the initial value expression for the property"</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">So if I understand it right if I reset "y" "functionWithSideEffects" gets executed.</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">------------</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div>Can you explain what is the difference between "<b>Self</b>" and "<b>Value</b>" in the following example?:</div><div><br></div><div><div>protocol Fungible {</div><div> typealias Fungus</div><div> func funge() -> Fungus</div><div>}</div><div><br></div><div>var behavior runcible<Value where Self: Fungible, Self.Fungus == Value>: Value {</div><div> get {</div><div> return self.funge()</div><div> }</div><div>}</div></div><div><br></div><div>Isn't "Self" the same as "Value"? So it can be rewritten to:</div><div><br></div><div><div><span style="background-color: rgba(255, 255, 255, 0);">var behavior runcible<Value: Fungible, Value.Fungus == Value>: Value {</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"> get {</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"> return self.funge()</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"> }</span></div><div><span style="background-color: rgba(255, 255, 255, 0);">}</span></div></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">----------</span></div><div><br></div><div>You've wrote that <b>behaviors shouldn't be types/type-like</b> e.g. "var x: lazy<Int>".</div><div>Can you mention some disadvantages?</div><div><br></div><div>I can't see huge ones. However I don't see any advantages.</div><div><br></div><div>Is there any advantage regarding a type-like behavior?</div><div><br></div><div>---------</div><div><br></div><div>I just remembered recursive value types...</div><div>We can even eliminate another keyword: "<b>indirect</b>"</div><div><br></div><div>implementation:</div><div><br></div><div>var behavior indirect<Value>: Value {</div><div> class Ref<T> {</div><div><span style="background-color: rgba(255, 255, 255, 0);"> var value: T</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"> init(_ value: T) { self.value = value }</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"> }</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);"> var reference: Ref<Value> = Ref(initialValue())</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"> get { return reference.value }</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"> set { reference.value = newValue }</span></div><div>}</div><div><br></div><div><br></div><div>I'm glad you made it so far :)</div><div>- Maximilian</div><div></div></body></html>