-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Zach Eriksen
committed
Sep 29, 2020
1 parent
9e2fd46
commit 696f9f0
Showing
4 changed files
with
118 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// Control.swift | ||
// E.num | ||
// | ||
// Created by Zach Eriksen on 9/29/20. | ||
// | ||
|
||
enum Control { | ||
case `if`(Bool, Function) | ||
case `else`(Bool, Function) | ||
case ifElse(Bool, Function, Function) | ||
case loop(ClosedRange<Int>, Function) | ||
case forEach([Variable], Function) | ||
case forever(Function) | ||
} | ||
|
||
extension Control { | ||
func run() { | ||
switch self { | ||
case .if(let condition, let function): | ||
if condition { | ||
function() | ||
} | ||
case .else(let condition, let function): | ||
if !condition { | ||
function() | ||
} | ||
case .ifElse(let condition, let trueFunction, let falseFunction): | ||
if condition { | ||
trueFunction() | ||
} else { | ||
falseFunction() | ||
} | ||
case .loop(let range, let function): | ||
for value in range { | ||
function.run(.int(value)) | ||
} | ||
case .forEach(let values, let function): | ||
for value in values { | ||
function.run(value) | ||
} | ||
case .forever(let function): | ||
while true { | ||
function() | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters