[swift-users] import module into REPL

Kate Stone k8stone at apple.com
Tue Dec 22 16:00:15 CST 2015


There isn’t a mechanism for importing definitions from source as a module in the REPL currently, though it would make a perfectly reasonable enhancement and might constitute an interesting project for someone motivated to do so.  Using the existing REPL you have two options:

Compile the source as a library with public entry points and invoke the REPL with -l<library-path> to make it available during a REPL session.
Copy and paste a source file into the REPL.  The input system automatically recognizes when code is being pasted and disables automatic formatting and completion detection.  Pressing return after the paste operation will parse the entire buffer as one compilation unit, making all of the relevant declarations available for subsequent use.

Kate Stone k8stone at apple.com <mailto:k8stone at apple.com>
 Xcode Low Level Tools

> On Dec 22, 2015, at 1:38 PM, Jonas Fredriksson via swift-users <swift-users at swift.org> wrote:
> 
> if I have a source code in file A, how can I compile it as an module and import it to REPL (I am using swift on ubuntu)? 
> I am looking for something similar like %run in ipython. 
>  _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20151222/32aba8c7/attachment.html>


More information about the swift-users mailing list