Lesson 13 (2019) discussion and wiki

The best forum is swift@tensorflow.org. Join in at: Redirecting to Google Groups

1 Like

The %install directive is used to install Swift Package Manager packages!
Think of this like !pip install commands that run inline in your notebook.

See here for more info!

1 Like

I understand that part, it just seems an arbitrary and irrelevant name. Are there any explanations of why in is used? in makes me think that the first part is somehow part of the second part or maybe it comes from the second part, and it makes my brain stuck when I see it.

1 Like

Low level objects like float and array are defined in a Swift library file.

  1. Are these then pre-compiled to machine code?

  2. Do we have confidence that this generated code is as good as what a human programmer would write?

  3. When basic types are extended, how or when is the extension compiled? Or is it interpreted?

Obviously I am concerned with execution speed and interpreter responsiveness.

You raise some good points. Check out the Swift forum post linked by @marcrasi for some historical context.

Here’s a thread on the Swift forum about the in keyword in the closure syntax. You’ll find historical reasons explained by some early engineers on the Swift project including Joe Groff and Chris himself. Hope this provides some more context!

Ah, I just noticed that @marcrasi already posted it above!

Over 9000 times faster…

3 Likes
  1. They are compiled when the standard library is compiled (typically distributed with the compiler).
  2. Check out the GodBolt compiler explorer where you can see the generated assembly. In general, it’s pretty good. (e.g. check out: Compiler Explorer or the spelled-as-an-extension-alternative: Compiler Explorer)
  3. They are compiled when the extension is compiled, or in the case of Jupyter when you run the cell that defines the extension. (They are not interpreted.)

Is there any web frameworks similar to Flask or Django for Swift yet?

1 Like

There are things like Vapor and Kitura. Not sure how close they are to Flask and Django though.

1 Like

Do you know how it compares to Flask / Django?

Vapor looks pretty Flasky to me at the highest level

2 Likes

Vapor. Kitura. Perfect.

IBM is a backer of Kitura.

1 Like

How do we know that calling f() is not optimized away in this case because of e.g. lack of side effects detected by the compiler?

1 Like

Here was my attempt at a webserver for Swift, it’s very much half-baked, but Swift is great for server stuff!

1 Like

Wow: %install libraries straight from github… just realized now :wink:

4 Likes

Swift.org has a Swift Server Work Group led by Vapor, Kitura and SwiftNIO project members. The group is backing a few projects such as SwiftNIO and swift-log.

2 Likes

Yes! Here’s an excellent comparison of two Swift web frameworks, Vapor vs Kitura.
Check it out to see snippets of the frameworks (route registration, asynchronous code, etc).

In short:

  • Kitura APIs are more similar to existing industry-adopted frameworks (like Node.js/Express.js).
  • Vapor APIs are designed from the ground-up using Swift.
3 Likes

Just to confirm, are you referring to the time function?

1 Like

From here, I think: https://github.com/google/swift-jupyter/commit/1e08b1dc0f5986e424fac3a2bd267873ad17efcb