a little more object oriented
I added the ability to call methods inside structs.
a call to a function inside a struct will pass the struct as first parameter implicitly.
with this we get a behaviour similar to python where methods are just functions that receive an object as first parameter (normally called self).
here are some examples:
@public present = fn (Self) io.format("Hi!, I'm ~s ~s, my email is ~s~n", [@Self.firstname, @Self.lastname, @Self.email]) @public new = fn (Firstname, Lastname, Email) New = { firstname: Firstname, lastname: Lastname, email: Email, show: fn struct.print:1, present: fn present:1} New @public run = fn () P = new("mariano", "guerra", "foo@bar.com") @P.show() @P.present()
as you can see, the instantiation of the new struct is similar to javascript.
running the program displays:
<struct firstname="mariano" lastname="guerra" email="foo@bar.com"/> Hi!, I'm mariano guerra, my email is foo@bar.com
I also added pretty printing of structs in the erlang shell and some more functions to the struct module
>>> P = person.new("mariano", "guerra", "foo@bar.com") <struct firstname="mariano" lastname="guerra" email="foo@bar.com"/> >>> @P.firstname "mariano" >>> struct.print(P) <struct firstname="mariano" lastname="guerra" email="foo@bar.com"/> ok >>> S = {foo: 1, bar: "asd", baz: true, show: fn struct.print:1} <struct foo=1 bar="asd" baz=true/> >>> @S.show() <struct foo=1 bar="asd" baz=true/> ok >>> struct.print(S, true) <struct foo=1 bar="asd" baz=true show=#Fun<struct.print.1>/> ok