Skip to content

Instantly share code, notes, and snippets.

@Europia79
Last active December 19, 2017 12:34
Show Gist options
  • Save Europia79/78bf804f7630a6a64ebf7cade1ce219e to your computer and use it in GitHub Desktop.
Save Europia79/78bf804f7630a6a64ebf7cade1ce219e to your computer and use it in GitHub Desktop.
[C%] Experimental syntax called Function Builder Notation
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
@Europia79
Copy link
Author

Europia79 commented Dec 15, 2017

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment