-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Editorial: Increase consistency and clarity of string operations #2974
Conversation
spec.html
Outdated
1. Let _hexDigits_ be the substring of _string_ from _k_ + 1 to _k_ + 3. | ||
1. Let _parseResult_ be ParseText(StringToCodePoints(_hexDigits_), |HexDigits[~Sep]|). | ||
1. If _parseResult_ is not a Parse Node, throw a *URIError* exception. | ||
1. Let _B_ be the unsigned 8-bit value corresponding with the MV of _parseResult_. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These re-use the aliases _hexDigits_
, _parseResult_
, and _B_
, so should use Set-to
syntax rather than Let-be
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I consider these to be separate aliases in a deeper scope that shadow those in the outer scope, which has the joint benefits of a) matching likely implementation where shadowing is available, and b) allowing reuse of the pattern without gratuitous variation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I consider these to be separate aliases in a deeper scope that shadow those in the outer scope,
That's reasonable from a programming language point of view, but I don't think there's anything in the spec that supports it. E.g., 5.2 "Algorithm Conventions" doesn't say anything about scopes or shadowing. It could, but my guess is, that would be more bother than it's worth.
Anyway, I'll leave it to the editors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @jmdyck; we don't currently define any scoping rules except for Abstract Closures, and it's not worth the complexity of doing so vs just picking different aliases or (my preference here) using Set
.
Also, nested scoping would conflict with the current pattern of
1. If condition,
1. Let _x_ be 1.
1. Else,
1. Let _x_ be 2.
1. Use _x_.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I meant "deeper scope" from a logical perspective rather than algorithmic. AFAICT from Algorithm Conventions, Let _x_ be …
after a preceding Let _x_ be …
is not an error and has the effect of declaring a new alias that shadows the previous one temporally rather than lexically (i.e., "may be referenced in any subsequent steps"), which in the case of this algorithm are indistinguishable anyway because these declarations are in the same loop body (itself also supporting the "temporal shadowing" interpretation because each iteration encounters the same Let
steps) and there are no references at decreasing indentation.
As noted above, I think that switching to Set
would result in gratuitous variation for identical logic:
1. Let _hexDigits_ be the substring of _string_ from _k_ + 1 to _k_ + 3.
1. Let _parseResult_ be ParseText(StringToCodePoints(_hexDigits_), |HexDigits[~Sep]|).
1. If _parseResult_ is not a Parse Node, throw a *URIError* exception.
1. Let _B_ be the unsigned 8-bit value corresponding with the MV of _parseResult_.
1. …
1. If _n_ = 0, then
1. …
1. Else,
1. …
1. Repeat, while _j_ < _n_,
1. …
- 1. Let _hexDigits_ be the substring of _string_ from _k_ + 1 to _k_ + 3.
- 1. Let _parseResult_ be ParseText(StringToCodePoints(_hexDigits_), |HexDigits[~Sep]|).
+ 1. Set _hexDigits_ to the substring of _string_ from _k_ + 1 to _k_ + 3.
+ 1. Set _parseResult_ to ParseText(StringToCodePoints(_hexDigits_), |HexDigits[~Sep]|).
1. If _parseResult_ is not a Parse Node, throw a *URIError* exception.
- 1. Let _B_ be the unsigned 8-bit value corresponding with the MV of _parseResult_.
+ 1. Set _B_ to the unsigned 8-bit value corresponding with the MV of _parseResult_.
If that is indeed the editorial preference, I think I would instead encapsulate it in a micro-operation, e.g.:
- 1. Let _hexDigits_ be the substring of _string_ from _k_ + 1 to _k_ + 3.
- 1. Let _parseResult_ be ParseText(StringToCodePoints(_hexDigits_), |HexDigits[~Sep]|).
- 1. If _parseResult_ is not a Parse Node, throw a *URIError* exception.
- 1. Let _B_ be the unsigned 8-bit value corresponding with the MV of _parseResult_.
+ 1. Let _B_ be ReadHexOctet(_string_, _k_ + 1).
+ 1. If _B_ is not an integer, throw a *URIError* exception.
1. …
1. If _n_ = 0, then
1. …
1. Else,
1. …
1. Repeat, while _j_ < _n_,
1. …
- 1. Let _hexDigits_ be the substring of _string_ from _k_ + 1 to _k_ + 3.
- 1. Let _parseResult_ be ParseText(StringToCodePoints(_hexDigits_), |HexDigits[~Sep]|).
- 1. If _parseResult_ is not a Parse Node, throw a *URIError* exception.
- 1. Let _B_ be the unsigned 8-bit value corresponding with the MV of _parseResult_.
+ 1. Let _continuationByte_ be ReadHexOctet(_string_, _k_ + 1).
+ 1. If _continuationByte_ is not an integer, throw a *URIError* exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the call today, editors are in agreement that we don't want to do this kind of shadowing. If you want to introduce a new AO here that's fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
c0105cf
to
870ad44
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM other than nits.
Thanks @jmdyck; good suggestions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks okay to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm % small comments
2dc4f8e
to
5cf7099
Compare
There was a lot of gratuitous divergence between Encode, Decode, escape, and unescape, and also between those operations and other string operations.
Non-comprehensive improvements:
code {unit,point} whose numeric value is…
phrasing rather thancode {unit,point} whose value is…
.Let _len_ be the length of…
over alternate aliases for_len_
.Repeat, while _k_ < _len_
iteration over alternatives likewhile _k_ ≠ _len_
or embeddedIf _k_ = _len_, return…
.