silbinarywolf / proposal-fel

FEL Programming Language Design Documents
3 stars 0 forks source link

Optional `for` item scope name #3

Closed jerricco closed 7 years ago

jerricco commented 7 years ago

This will probably be in line with Silverstripe/Twig loops, which implicitly uses the scope of the current item, but not sure. Might have something like: "for MyList {" wherein you access properties with "it.Name" Reasoning for this is so that when reading the code, you immediately know if the code your reading is in a "for" loop context. Also means you dont need special "top" or "up" variables to access parent scopes.

I like this idea, but sure it wouldn't hurt to add an optional name for your scope item. Wherin:

//Implicit
for MyList {
    // MyList props accessed like: it.Name
}

//Named
for item in MyList {
    // item.Name
}

Just think the option means more idiomatic code for developers to get on board (part of why I've seen people even shy away from python lel).

jerricco commented 7 years ago

I suppose some further reasoning here is that a lot of the skimming I do through code, I let my syntax highlighter and (hopefully) good indentation to tell me where I am in the code more than spotting actual construct names.

I tend to do all that parsing once I know where I am and what I'm doing, so I don't think this will detract too much from the idea that spotting an it denotes a for construct. This could also be enforced by linters if someone doesn't want to allow named/implicit (either/either).

jerricco commented 7 years ago

Nvm just read this

// Iterator Loop, explicit iterator value
for link := socialLinks {
    Link(url=link.url) {
        i(class="fa fa-"+link.icon)
        link.title // Print `title`
    }
}

Too bushwhacked for this.