Skip to content

Instantly share code, notes, and snippets.

@onelivesleft
Created January 30, 2017 00:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onelivesleft/913e8dbfdf0adcb999313d257b5437a3 to your computer and use it in GitHub Desktop.
Save onelivesleft/913e8dbfdf0adcb999313d257b5437a3 to your computer and use it in GitHub Desktop.
Unsolicited language feature suggestions
/* If you are getting bombarded with suggestions then I apologise for joining the throng.
I really like the direction you are going with Jai, and these ideas came to me
unbidden; I thought I should share them: */
// 1. Generalise 'else' so it works on any given code block: it executes if the preceding
// block did not. Predominately this would be for 'for' and 'while' loops.
// For example:
if message {
while message {
printf(message.text);
message.next();
}
} else {
printf("No messages!\n");
}
// becomes:
while message {
printf(message.text);
message.next();
} else {
printf("No messages!\n");
}
// 2. An 'until' keyword, which executes if the preceding block wasn't broken out-of
// with a 'break' statement. This common search idiom:
index := -1;
for items {
if it.name == looking_for {
index = it.index;
break;
}
}
if index == -1 {
panic();
return;
}
// [code utilising index]
// becomes:
for items {
if it.name == looking_for {
index := it.index;
break
}
} until {
panic();
return;
}
// [code utilising index]
// ...which is not only cleaner, but also doesn't rely on picking a sentinel value (or using
// a secondary 'found' bool). Also also, 'index' isn't created if the correct item is not
// found: I'm not sure if that's useful or not, but it is kinda interesting.
// 3. The idea of a 'broken' keyword also occured, where the block executes if
// the previous block exited with a 'break'... but I can't think of a use case for it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment