Skip to content

[SUGGESTION] About what classes can possibly look like #584

Description

@burbokop

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.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions