-
Notifications
You must be signed in to change notification settings - Fork 265
Closed
Labels
Description
Some kind of classes already implemented in cppfront.
#include<functional>
cat: (_name: std::string, _color: std::string) -> (
name: std::string,
color: std::string,
say_meow: std::function<void()>
) = {
name = _name;
color = _color;
say_meow = : () = { std::cout << "Meow from cat '(name$)$' with color '(color$)$'" << std::endl; };
}
main: () = {
my_cat: _ = cat("my_cat", "white");
std::cout << "cat '" << my_cat.name << "' created." << std::endl;
my_cat.say_meow();
}
This code is perfectly compiled with latest version of cppfront (commit 9ca2f45).
cat function is both a constructor and class itself. Something similar implemented in scala language where class declaration syntax is just like function declaration syntax but with additional class keyword.
If there were ability to pass self parameter to say_nya: std::function<void()> which refers to cat__ret structure than it would be more look like a member function.
Conclusion: May be cpp2 does not need special syntax for classes, almost everithing that needed is already here.
Thank you for your work.