[swift-users] Question out of curiosity: why "func"

Chris Lattner clattner at apple.com
Thu Apr 7 23:44:14 CDT 2016

> On Apr 4, 2016, at 7:25 AM, Jim Malak via swift-users <swift-users at swift.org> wrote:
> My background going into Swift was everything but JavaScript. One thing I often wondered about (usually every time I forgot to type it) is what purpose does requiring the keyword “func” serve when defining or decaling a function in Swift. I am not a compiler expert but intuitively it would seem that the function signature could be readily recognized by the complier and people alike with the presences of the ()’s at the end.

Swift’s grammar follows a very regular structure, where declarations are introduced with a keyword.  This structure has a number of advantages when parsing.  For example, it allows “modifiers” like “mutating” and “public” to be context sensitive identifiers instead of themselves being keywords.  It also helps with more subtle things like error recovery in the face of invalid code that produces parsing errors.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160407/2a3ef391/attachment.html>

More information about the swift-users mailing list