Skip to content

Instantly share code, notes, and snippets.

@erica
Last active July 27, 2016 17:13
Show Gist options
  • Save erica/a78045d09fa5bb20e6e566295140c84d to your computer and use it in GitHub Desktop.
Save erica/a78045d09fa5bb20e6e566295140c84d to your computer and use it in GitHub Desktop.

Introducing Goto

  • Proposal: SE-0666
  • Author: Erica Sadun
  • Status: Draft
  • Review manager: Crusty

Introduction

This proposal introduces goto to Swift.

Motivation

In a nutshell, the tl;dr of this is "Mike Ash dared me."

Introducing "goto" permits a one-way transfer of control to another point in code under a common scope. Wikipedia writes: "Many languages support the goto statement, and many do not." Right now Swift does not.

Swift is an opinionated language, and in its opinion, all the effort people go to just to avoid a simple goto places an undue burden on coders, especially on Monday mornings with suboptimal levels of coffee.

Detailed Design

  • Swift already supports labels for continue and break.
  • Labels are extended to any point in code, not just at loops.
  • A goto statement redirects execution to that label.
label: 

...

goto label

Impact on Existing Code

This proposal is purely additive. Theoretically it could break any code that uses goto as a symbol but it's self evident that anyone who has done so deserves to have their code broken.

Alternatives Considered

comefrom is computationally less practical.

@jeremy-w
Copy link

Follow-up: Allow storing labels in label references. This enables straightforward implementation of an indirect-threaded interpreter, and would be analogous to the GCC extension "Labels as Values".

@stephentyrone
Copy link

A necessary feature for any systems programming language!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment