Skip to content

Conversation

@timotheecour
Copy link
Member

close #18092

Copy link
Collaborator

@alaviss alaviss left a comment

Choose a reason for hiding this comment

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

Please also document that elif have to come after of. The manual is the language specification so we would want these details documented.

@timotheecour
Copy link
Member Author

done

@Varriount
Copy link
Contributor

While this technically documents "elif" in case statements (and is an improvement), I feel that there should be some additional explanation. Before this PR, I wasn't even aware that case supported elif, and I'm still not sure what it does, and when it should be used.

From the example, appears that elif allows the introduction of an arbitrary condition in a case statement? The example implies that it's only allowed at the end of a case statement, but is that true?

@timotheecour
Copy link
Member Author

timotheecour commented May 26, 2021

i feel it's clear enough and un-ambiguous as written, but feel free to suggest an alternative wording as code review comment.

I'm still not sure what it does, and when it should be used.

exactly what you wrote: From the example, appears that elif allows the introduction of an arbitrary condition in a case statement?

The example implies that it's only allowed at the end of a case statement, but is that true?

within a case statement, yes

@alaviss
Copy link
Collaborator

alaviss commented May 26, 2021

The code example is not the spec, it's... an example.

We already have a decent amount of writing right below it, and I think we should expand the paragraph talking about else to talk about elif as well.

@timotheecour
Copy link
Member Author

timotheecour commented May 26, 2021

The code example is not the spec, it's... an example.

yes and no; in this case I agree (and have updated spec description), but in other cases (in particular description of edge cases in APIs) it may makes sense to treat examples as spec because the alternative would be both non-DRY and add no value for readers compared to a well written (and compiler checked) runnableExamples.

I also mentioned the special case of string and mentioned the spec might change (refs #11474 (comment))

timotheecour referenced this pull request May 26, 2021
@Varriount
Copy link
Contributor

The behavior an example describes tends to be implicit - my previous comment on elif's behavior was a guess. If not repeating information is a priority here, it would be preferable to go with an explicit description of elif's behavior over an implicit example.

@Araq
Copy link
Member

Araq commented May 31, 2021

The spec should say something like: "elif" in "case" is handled just like "else: if".

@timotheecour timotheecour force-pushed the pr_close_18092_case_elif branch from 7955470 to e4adcca Compare May 31, 2021 19:32
@timotheecour
Copy link
Member Author

PTAL

@Araq Araq merged commit 60cbdbf into nim-lang:devel May 31, 2021
@timotheecour timotheecour deleted the pr_close_18092_case_elif branch May 31, 2021 20:21
PMunch pushed a commit to PMunch/Nim that referenced this pull request Mar 28, 2022
* close nim-lang#18092 [skip ci] document elif in case statements

* fixup

* clarify spec; mention special rule for string in case statements

* address comments
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.

elif in case statement is not documented in the manual

4 participants