<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>Patrick,<br></div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">I think you're making valuable points here. I also can't think of cases where you wouldn't also import a module in case it was found to be importable. So the use cases I can think of could as well be tackled by allowing expressions such as `import Foo.Bar` as compile-time checks within the conditions of `#if` like you suggested. That would bring those libraries only visible within the scope of that block.</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">However, there can be cases where you're considering importing more than one module, so something like:</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature"> #if import Foo, import Bar</div><div id="AppleMailSignature"> ...</div><div id="AppleMailSignature"> #elseif import Baz</div><div id="AppleMailSignature"> ...</div><div id="AppleMailSignature"> #endif</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">should be considered in that design too. And I don't like the fact that it would import many modules in one line of code.</div><div id="AppleMailSignature"><br></div><div id="AppleMailSignature">However, I don't get your concerns of "whether already imported or not". Isn't `import` strictly about bringing identifiers of linked libraries visible in the current file and not about <i>linking</i> to libraries in code.</div><div><br></div><div>— Pyry</div><div><br></div><blockquote type="cite"><div><span>I guess one issue I can see is it’s used in two different ways:</span><br><span>- The first use of canImport is used to check whether it can import a module, and then does so, but there’s no requirement for it to do so. Is this the right this to do?</span><br><span>- The second use of canImport makes no guarantee that the module has been imported, only that it can.</span><br><span></span><br><span>What if instead `import` could return whether it imported or not, when used with #if? Instead of ‘can import’, you get ‘did just import’ and ‘has imported’.</span><br><span></span><br><span></span><br><span>import Required // Error if not present, current behaviour</span><br><span></span><br><span>#if import CoolThing // Skips code block if not present, imports otherwise</span><br><span> // Do something with CoolThing module</span><br><span>#else</span><br><span> import AlmostAsCoolThing</span><br><span>#endif</span><br><span></span><br><span>and you test at the use-site</span><br><span></span><br><span>#if module(X) // Does not import, only checks if it has been imported</span><br><span> // use things that are available in X</span><br><span>#else</span><br><span></span><br><span></span><br><span>As per Pyry’s feedback, you could add a version:</span><br><span></span><br><span>#if import Frobnication(<1.7.3) // <- Only added version constraint here.</span><br><span>extension Knob : Frobnicatable { ... }</span><br><span>#endif</span><br><span></span><br><span></span><br><span></span><br><span>Just a way to make it less low level.</span><br><span></span><br><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></body></html>