-
Notifications
You must be signed in to change notification settings - Fork 147
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
feat(Syntax addition): to match language style, "for item in myList indexed by i" #544
base: dev
Are you sure you want to change the base?
Conversation
New test results with the 2 new tests for the 2 new syntaxes |
I just realized, should I remove the built versions from this PR? |
dist/_hyperscript.js
Outdated
@@ -5627,7 +5627,11 @@ | |||
} | |||
} | |||
|
|||
if (tokens.matchToken("index")) { | |||
if (tokens.matchToken("index") || tokens.matchToken("by")) { | |||
var identifierToken = tokens.requireTokenType("IDENTIFIER"); |
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.
dumb but can you move the "by" match inside the if statement to be symmetric w/ the other side? Also should we add the "with" option as well?
for x in foo indexed with ...
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.
no to question 1 unfortunately.
This if statement is
if(tokens.matchToken("index") || tokens.matchToken("by")) {
because it allows for
for x in foo by i
in addition to
for x in foo index i
And then this PR also adds a
for x in foo indexed by i
If I move the "by" match inside the if statement that drastically changes what the PR does.
Instead of for x in foo by i
it would instead allow
for x in foo index by i
in addition to
for x in foo indexed by i
BUT it then might break for x in foo index i
because you could then no longer name your variable by
without using the indexed
form if you do that. Thats why I chose indexed
instead of index
for the multi-word form. It otherwise might screw up what was previously the only indexing clause that existed before, which is index
I could, however, add the extra syntax you suggest for with
to the PR
for x in foo indexed with i
although I worry that at a certain point it starts running into a readability issue, especially if you also decide you want a with
keyword that means something different somewhere else. Its a much more multipurpose word than by
is.
Maybe we could use with
instead of by
? And then later you could make it more general to encompass other scoping operations, and it would fit right in? Im not that picky really I just think the only option being index
on its own is a really unsatisfying one because there is almost no circumstance where it reads as well as the rest of the language.
Doing with
instead of by
, this PR would then allow
(1)
for x in foo with i
for x in foo index i
for x in foo indexed with i
rather than
(2)
for x in foo by i
for x in foo index i
for x in foo indexed by i
Doing it in addition, it would probably be best to only allow
(3)
for x in foo by i
for x in foo index i
for x in foo indexed by i
for x in foo indexed with i
So, yeah, of these 3 options of available syntaxes above, which should be the winning implementation? All 3 are simple to achieve and add, but you are the one who should decide between the 3
I personally prefer option 2 which is what this PR implements, unsure which of the other 2 I like better, which is why I didnt choose them, but they are fine, and I would be ok with either.
Option 2 is my favorite though because I feel it will lead to less ambiguity in the long run, as with
is a keyword that is more likely to be used somewhere else compared to by
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.
mmm, I see
i don't like the for x in foo by i
syntax, I think I like 2 minus the first option.
Are you good w/ that?
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.
yeah sure. Sounds good to me. I liked its succinctness but if you dont like it Im happy with people who care about it reading like english typing out indexed by
and people who dont using index
.
I will get to this soon, along with removing the build artifacts from the commit because im assuming you probably run the build yourself anyway for security reasons so that you KNOW whats in the gzip.
Im pretty sure I just need to remove the check for 'by' to achieve the desired syntax, and remove the test for it and its mention in the readme, about to go try it out
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 :)
for item in myList by i Support for both of the above index clauses because the normal one reads terribly in a language that otherwise reads amazingly. for item in myList index i
for item in myList indexed by i
for item in myList by i
Edit: no longer offers this second extra syntaxSupport for both of the above index clauses because the normal one reads terribly in a language that otherwise reads amazingly.
The one way to do it before was obviously only
for item in myList index i
An example of the new syntax from a project
As opposed to