Skip to content
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

Adds List.last #816

Merged
merged 2 commits into from
Dec 22, 2020
Merged

Adds List.last #816

merged 2 commits into from
Dec 22, 2020

Conversation

celsobonutti
Copy link
Contributor

Adds List.last operation (see #664):
List.last : List elem -> Result elem [ ListWasEmpty ]*

(list_var, Var(Symbol::ARG_1)),
(
len_var,
// Num.sub (List.len list) 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's cool

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the right approach for now, but actually we should use subWrap from #664 (once that's been implemented), because Num.sub should do overflow checking, and there's no chance of overflow yet.

(I say "should do" because currently only Num.add actually does it...maybe that's a good next project, actually!)

Copy link
Contributor

@rtfeldman rtfeldman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! 🎉

Thanks @celsobonutti!

@@ -282,6 +282,23 @@ mod repl_eval {
expect_success("List.sum [ 1.1, 2.2, 3.3 ]", "6.6 : F64");
}

// TODO add test cases for empty lists once error messages in the repl are correct
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure enough! I've filed a bug for this: #818

(list_var, Var(Symbol::ARG_1)),
(
len_var,
// Num.sub (List.len list) 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the right approach for now, but actually we should use subWrap from #664 (once that's been implemented), because Num.sub should do overflow checking, and there's no chance of overflow yet.

(I say "should do" because currently only Num.add actually does it...maybe that's a good next project, actually!)

@rtfeldman rtfeldman merged commit 1cdc048 into trunk Dec 22, 2020
@rtfeldman rtfeldman deleted the add_list_last branch December 22, 2020 04:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants