[swift-evolution] Proposal: Introduce User-defined "Dynamic Member Lookup" Types
Magnus Ahltorp
map at kth.se
Sun Dec 3 21:38:55 CST 2017
> 4 Dec. 2017 11:17 Letanyan Arumugam via swift-evolution <swift-evolution at swift.org> wrote:
>
> The most minimal way of marking expressions in a way I could think of that would also remove anyones notion of "this code is fully supported static Swift code” would be to use the currently reserved ‘ (Single quote).
>
> Using the code example from another conversation:
>
> let np = Python.import("numpy")
> let x = np.array([6, 7, 8])
> let y = np.arange(24).reshape(2, 3, 4)
>
> let a = np.ones(3, dtype: np.int32)
> let b = np.linspace(0, pi, 3)
> let c = a+b
> let d = np.exp(c)
> print(d)
>
> Would become:
>
> let np = Python.import("numpy")
> let x = 'np.array([6, 7, 8])'
> let y = 'np.arrange(24).reshape(2, 3, 4)'
>
> let a = 'np.ones(3, dtype: np.int32)'
> let b = 'np.linespace(0, pi, 3)'
> let c = a+b
> let d = 'np.exp(c)’
> print(d)
1. a+b is also is a dynamic method call in this example. How would you explain to a programmer that they have to use single quotes around some expressions but not others?
2. Having this kind of special syntax would feel very arbitrary to the programmer, and hard to look up. Fixits would of course be able to help here, but if the compiler already knows what you should write, why does it require it? Which brings me to my third point:
3. This feels like punishment, like Python making a special syntax for static language bridges where they have to use the phrase "static_typing_is_for_losers" in front of every method call.
It's not like dynamic method calls will appear in your code if you don't use these kind of bridges, and even if you do, it will only be when you call methods on that bridge's types. When you call a method on an object, you already have to know what that object does, or you will be in trouble.
/Magnus
More information about the swift-evolution
mailing list