[swift-evolution] Proposal: Introduce User-defined "Dynamic Member Lookup" Types

Pertti Kröger pertti.kroger at qvik.fi
Tue Dec 5 02:27:39 CST 2017


I do not really have a strong opinion on whether this feature should be
added to the language, though I will say that if it is, I do not see the
need to enforce the visibility of failability on a language level. The
feature as proposed is, as has been restated many times, entirely safe. A
sane language wrapper implemented using this would likely deal with
optionals at every corner, but the feature itself can, and in my opinion
should, be as generic as possible.

That said, I feel that this discussion has lacked mention of what is
actually possible in Swift today. Sure, this:

>> let d = np.call(member: "array", args: Python.array(6, 7, 8),
>>                 kwargs: [("dtype", "i2")])

looks positively hideous, but with some operator cleverness, one can get
things like:

val.."prop" // get property prop of val
val.."prop".."turboprop" // get property turboprop of property prop of val
val.."prop" <- newProp // set property prop of val to newProp
val.."prop".."func"..[arg1, arg2] // call function func of property prop of
val with arguments (arg1, arg2)

to compile, and indeed to do sensible things. I believe this sort of DSL-y
hacks already enabled by Swift should be taken into consideration when
assessing the necessity of this feature and the dynamic calling syntax one.
 -Pertti
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20171205/312e4138/attachment.html>


More information about the swift-evolution mailing list