<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><br></div><div><br>On 4 Aug 2016, at 13:00, Raphael Sebbe <<a href="mailto:raphael@creaceed.com">raphael@creaceed.com</a>> wrote:<br><br></div><blockquote type="cite"><div dir="ltr">Thank you Chris, James.<div><br></div><div>I'm answering James feedback/questions below.<br><br><div class="gmail_quote"><div dir="ltr">On Thu, Aug 4, 2016 at 1:57 AM James Froggatt <<a href="mailto:james.froggatt@me.com">james.froggatt@me.com</a>> wrote:</div><div dir="ltr"><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div>What are your thoughts on using tuples for this? </div><div><br></div><div>typealias CGPoint4 = (CGPoint, <span style="background-color:rgba(255,255,255,0)">CGPoint, CGPoint, CGPoint)</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)">struct Quad { var corners: CGPoint4 }</span></div><div><span style="background-color:rgba(255,255,255,0)"><br></span></div><div><div><span style="background-color:rgba(255,255,255,0)">var fixedLength = (point1, point2, point3, point4)</span></div><div><span style="background-color:rgba(255,255,255,0)">print(fixedLength.0)</span></div><div><span style="background-color:rgba(255,255,255,0)">print(fixedLength.4) //compiler error, not an element of the tuple</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)">With shorthand declaration syntax, this would have the benefits of a fixed-length array with added compile-time safety. A previously suggested syntax was along the lines of '(CGPoint * 4)'.</span></div></div><div dir="auto"><br></div></blockquote><div><br></div><div>I investigated tuples a bit, it's close. The one thing I'd need is being able to index the values using a variable. The tuple.i notation apparently doesn't work (or I did not try hard enough). Also, for low-level things that will be mapped to GPU memory, precise/predictable/settable alignment is needed.</div></div></div></div></blockquote><div><br></div><div>Good point. A similar mechanism might be possible eventually for tuples, but right now this isn't possible.</div><br><blockquote type="cite"><div><div dir="ltr"><div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><blockquote type="cite"><div><div dir="ltr"><div>4. Reference/pointer to structs: accessing & modifying structs deep into the model currently requires fully qualified path to the struct instance. Fully qualifying an inner struct in your data model can be very tedious, depending on model complexity. </div><div> </div><div>For instance, with scoped access solutions made with Swift 3, you need to cascade blocks if you need to access multiple inner structs, which doesn't scale well as it creates code pyramids:</div><div><br></div><div>scopedAccess(&varA) { </div><div> scopedAccess(&varB) { </div><div> // modify varA & varB </div><div> } </div><div>}</div><div> </div><div>It's easily done in C/C++ using pointers/references. To make that better, we'd need some kind of language support IMO.</div></div></div></blockquote><div><br></div></div><div dir="auto"><div>Could this be generalised, maybe with a reference-semantic ‘property accessor’?</div><div><br></div><div>Example:</div><div><br></div><div>let get: () -> Bool = #get(controller.view.isVisible)</div><div>print(get())</div><div><br></div><div>let set: (Bool) -> () = #set(controller.view.isVisible)</div><div>set(true)</div><div><br></div><div>let accessor: Lens<Bool> = #lens(controller.view.isVisible)</div><div>print(accessor.value)</div><div>accessor.value = true</div><div><br></div><div>This would have the added bonus of also tracking the reassignment of reference-type properties - in this example, if 'view' is reassigned, the referenced value is updated.</div></div></blockquote><div><br></div><div>Sounds good, I'm not aware of this syntax. Will investigate, thanks.</div></div></div></div></div></blockquote><div><br></div><div>Sorry, I was suggesting a *possible* syntax. No such syntax currently exists, though the functionality can be imitated with closures:</div><div><br></div><div><div><span style="background-color: rgba(255, 255, 255, 0);">let get: () -> Bool = {controller.view.isVisible}</span></div><div><span style="background-color: rgba(255, 255, 255, 0);">print(get())</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);">let set: (Bool) -> () = {controller.view.isVisible = $0}</span></div><div><span style="background-color: rgba(255, 255, 255, 0);">set(true)</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);">struct Lens<T> {</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"> var get: () -> T</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"> var set: (T) -> ()</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"> var value: T { get { return get() } set { set(newValue) } }</span></div><div><span style="background-color: rgba(255, 255, 255, 0);">}</span></div><div><span style="background-color: rgba(255, 255, 255, 0);">let accessor: Lens<Bool> = Lens(get: {controller.view.isVisible}, set: {controller.view.visible = $0})</span></div><div><span style="background-color: rgba(255, 255, 255, 0);">print(accessor.value)</span></div><div><span style="background-color: rgba(255, 255, 255, 0);">accessor.value = true</span></div></div><div><br></div><div>It's a bit more verbose when creating the get-set accessor, and may not perform optimally, but it's actually pretty functional.</div><br><blockquote type="cite"><div dir="ltr"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><br><blockquote type="cite"><div><div dir="ltr"><div>5. Memory / pointer access, including casting. It's too verbose currently IMO when compared to C. Should be better supported for a language that is also targeting low-level (network, disk storage). A syntax that is both fast (like C) and safe would be great.</div></div></div></blockquote><div><br></div></div><div dir="auto"><div>Not familiar with low-level programming in Swift, but have you considered creating domain-specific operators?</div><div>For example, I imagine something like 'UnsafeMutablePointer(v)' could be reduced to '*v'.</div></div><div dir="auto"><div><br></div></div></blockquote><div><br></div><div>Do you mean operator is available only within a limited scope? That would be interesting, because I don't want to pollute global scope with such all-purpose operator. Sounds that I need to investigate that as well.</div></div></div></blockquote><div><br></div><div>If you have a specific module which performs this sort of operation a lot, you can just declare the operator as internal. If it's needed in several, making a separate module for the operators could be preferable.</div><br><blockquote type="cite"><div dir="ltr"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><br><blockquote type="cite"><div><div dir="ltr"><div>7. I'm also fan of async/await kind of stuff, asynchronous flows, etc., but this has already been mentioned -> cool!</div></div></div></blockquote><div><br></div></div><div dir="auto"><div>I would like to see some ideas in this area.</div><div>async/await never really clicked for me until I realised it's just syntactic sugar - 'await' actually ends the function, and everything below is an implicit callback. Personally I feel like Swift's trailing closure syntax makes callbacks lightweight enough that this isn't so much of an issue. Something focusing more on the memory-management and thread-safety aspects of asynchronous code does seem useful in the context of Swift.</div></div><div dir="auto"></div><div dir="auto"><blockquote type="cite"><div><br></div></blockquote></div></blockquote><div>Sure thread-safety, atomicity features would be really nice & useful. </div><div><br></div><div>The one problem I have with closure syntax (trailing or not, I like trailing too), is that when you chain a few of them, which is pretty frequent is async programming, you end up with a closure pyramid. It doesn't scale well beyond 2 or 3 levels.</div></div></div></blockquote><div><br></div><div>Makes sense.</div></body></html>