Last active
December 19, 2017 12:34
-
-
Save Europia79/78bf804f7630a6a64ebf7cade1ce219e to your computer and use it in GitHub Desktop.
[C%] Experimental syntax called Function Builder Notation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Main { | |
/** | |
* main() function that demonstrates the syntax of Function Builder Notation | |
* | |
* .returns(void) would be optional since it doesn't actually return anything | |
* .captures() is optional since it doesn't actually capture anything | |
* .throws() is optional since it doesn't actually throw any Exceptions | |
* | |
* This notation attempts to provide a consistent way to declare | |
* both global functions and locally scoped lambda functions. | |
*/ | |
fp main = fn(String[] args).returns(int).captures().throws() | |
{ | |
// fp = function pointer | |
fp lambda1 = fn() { }; // fn = pure function | |
fp lambda2 = fx() { }; // fx = impure function with side effects | |
fp lambda3 = fm() { }: // fm = function method with captured state | |
fp lambda4 = fm() { }; // automatically captures all local variables | |
fp lambda5 = fv() { }; // fv = virtual function with default behavior | |
fp lambda6 = fv(); // virtual function with no default behavior | |
return 0; | |
} // End of method main | |
// Example showing multiple return values | |
fp example1 = fv().returns(int, int); | |
// Example showing a function parameter & function return value | |
fp example2 = fv(fp<int>.r<int> param1).returns(fp<>.r<bool, int>); | |
} // End of class Main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
After reading a couple comments about the many different ways to declare a function in C++, I did a thought-experiment to try and come up with a more consistent way to declare functions: Both globally scoped functions and locally scoped lambda functions.
I'm calling my made-up language C% (pronounced C mod).
I'm not 100% sold yet on Function Builder Notation... probably because I'm so used to the C++ and Java syntax.
And also, this is just a first iteration on this concept.
I am interested on what others think... especially if you can suggest improvements. Thanks!