-
Notifications
You must be signed in to change notification settings - Fork 15
vine: overhaul control flow #314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
6aedc81
remove implicit `continue` from `loop`
tjjfvi 8d788a7
add while/else and for/else
tjjfvi dfbb30c
use while/else and for/else in examples
tjjfvi e96cde1
snaps
tjjfvi 0cb1d55
optimization: don't pass nil locals between stages
tjjfvi 0e1f32e
snaps
tjjfvi 7b2dd95
rework label handling
tjjfvi 50e418e
use new keyword label syntax
tjjfvi abe28ed
snaps
tjjfvi 3296a5c
make do a pseudo-statement
tjjfvi 72e6d0f
add when expression
tjjfvi 442a45e
remove else if
tjjfvi 52f837a
update *.vi
tjjfvi ace850f
snaps
tjjfvi 96051b6
allow non-divergent let-else
tjjfvi 80a24f1
parser: add check_then and eat_then
tjjfvi a4af54f
add `-> Type` annotations to control flow constructs
tjjfvi 5342438
snaps
tjjfvi 772980e
when_break_continue.vi
tjjfvi 36ecc65
let else match
tjjfvi aeeef47
add test for else match
tjjfvi 3740c39
make return/break/continue statements
tjjfvi ee10687
update *.vi
tjjfvi 6298d7a
snaps
tjjfvi 1f5cfc4
clippy
tjjfvi 96db9af
update misc test
tjjfvi f25c008
remove requirement for terminal arm in when
tjjfvi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
|
@@ -9,11 +9,14 @@ pub fn main(&io: &IO) { | |
|
||
for line in lines.into_iter() { | ||
let report = line.split(" ").map(fn* (x) { N32::parse(x).unwrap() }); | ||
if is_safe(report) { | ||
safe_count += 1; | ||
dampened_safe_count += 1; | ||
} else if problem_dampener(report) { | ||
dampened_safe_count += 1; | ||
when { | ||
is_safe(report) { | ||
safe_count += 1; | ||
dampened_safe_count += 1; | ||
} | ||
problem_dampener(report) { | ||
dampened_safe_count += 1; | ||
} | ||
} | ||
} | ||
|
||
F438
|
@@ -32,26 +35,28 @@ fn is_safe(report: List[N32]) -> Bool { | |
level - last | ||
}; | ||
if !(1 <= diff <= 3) { | ||
return false; | ||
break false; | ||
} | ||
if order is Some(order) && order != (last > level) { | ||
return false; | ||
break false; | ||
} | ||
order = Some(last > level); | ||
} | ||
last = Some(level); | ||
} else { | ||
true | ||
} | ||
true | ||
} | ||
|
||
fn problem_dampener(report: List[N32]) -> Bool { | ||
let prefix = []; | ||
let suffix = report; | ||
while suffix.pop_front() is Some(level) { | ||
if is_safe(prefix ++ suffix) { | ||
return true; | ||
break true; | ||
} | ||
prefix ++= [level]; | ||
} else { | ||
false | ||
} | ||
false | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.