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

feat(Syntax addition): to match language style, "for item in myList indexed by i" #544

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

BirdeeHub
Copy link
Contributor

@BirdeeHub BirdeeHub commented Jun 3, 2024

for item in myList indexed by i
for item in myList by i Edit: no longer offers this second extra syntax

Support 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

_="
on load put the children of the closest parent <div /> into myList
then for item in myList indexed by i
if the item's index does not exist
set the item's index to i
then set the item's id to item's id + '_' + i
"

As opposed to

_="
on load put the children of the closest parent <div /> into myList
then for item in myList index i
if the item's index does not exist
set the item's index to i
then set the item's id to item's id + '_' + i
"

@BirdeeHub
Copy link
Contributor Author

_hyperscript_tests.pdf

New test results with the 2 new tests for the 2 new syntaxes

@BirdeeHub BirdeeHub changed the title for item in myList indexed by i Syntax addition to fit the hyperscript style: for item in myList indexed by i Jun 3, 2024
@BirdeeHub BirdeeHub changed the title Syntax addition to fit the hyperscript style: for item in myList indexed by i Syntax addition to match language style: for item in myList indexed by i Jun 5, 2024
@BirdeeHub BirdeeHub changed the title Syntax addition to match language style: for item in myList indexed by i feat(Syntax addition): to match language style, "for item in myList indexed by i" Sep 20, 2024
@BirdeeHub
Copy link
Contributor Author

I just realized, should I remove the built versions from this PR?

@@ -5627,7 +5627,11 @@
}
}

if (tokens.matchToken("index")) {
if (tokens.matchToken("index") || tokens.matchToken("by")) {
var identifierToken = tokens.requireTokenType("IDENTIFIER");
Copy link
Contributor

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 ...

Copy link
Contributor Author

@BirdeeHub BirdeeHub Oct 12, 2024

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

Copy link
Contributor

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?

Copy link
Contributor Author

@BirdeeHub BirdeeHub Oct 21, 2024

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

Copy link
Contributor Author

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
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.

2 participants