SE-0195 — Introduce User-defined "Dynamic Member Lookup" Types

If we are going to allow variables to be callable, I think it should be independent of and orthogonal to dynamism.

If square-bracket subscript syntax is good enough for native Swift types to imitate being callable, then it is good enough for imported dynamic types as well. And if that syntax is *not* good enough for imported types, then it is not good enough for native types either.

Lets discuss DynamicCallable on its own thread when the topic comes up. Thanks.

2 Likes

I submitted an updated patch in PR14546. Thanks all!

11 Likes

If we ever get throwable properties, can this feature evolve to be implemented in such a way? That would make this feature more readable (try some.dynamic.property.chain vs. some?.dynamic?.property?.chain), far safer, and able to express proper errors. Frankly, I would gladly have traded the cleanness of property access for being able to throw errors now with try some().dynamic().property().chain(), but I guess that ship has sailed.

Also, as an aside, can the proposal be updated to reflect current Swift styling? It may be confusing to some if proposals don't reflect best practices in regards to recommended style (i.e. lower case enum cases).

Yes, this should compose directly and properly with throwing subscripts. I don't anticipate any problem with that, given that (at the end of the day) this is a syntactic sugar for existing underlying mechanics. Those mechanics define the semantics.

For anyone not following commits closely, FYI, the patch landed. We have @dynamicMemberLookup (including keypath support) in master now.

7 Likes

Great, thank you! Do you have an updated version of the PythonGlue.swift playground supporting the new attribute?

I would love to start playing with this :)

I have just installed the swift-DEVELOPMENT-SNAPSHOT-2018-02-17-a, the DynamicMemberLookup works.
Surprisingly, the compiler still produces the error message.
"Unknown attribute dynamicMemberLookup"

Thank you!

FWIW, I mentioned this proposal in a thread that I started on the FDB site -- asking about Swift language support:

https://forums.foundationdb.org/t/swift-language-support/53/16

It's the most viewed by far -- even with likes by FDB founders... so it looks like there is a bit of interest!

Super cool, I hope that the .call(member:) stuff will improve soonishly. I'm happy to see that you're finding this work useful.

-Chris