Overwrite default constructor

Is it possible to overwrite the default constructor like:

struct A
       field1
       field2
       field3
end

function A(f1, f2, f3)
       # do some operation here like log / parameters inspection
       # return a new instance here
end

I don’t actually know how to create a new instance, if I call A then it ends up an infinite recursion.

Yes. See the documentation for inner constructors. So for example in your case,

struct A
           field1
           field2
           field3
           function A(f1,f2,f3)
               return new(f1, f1+f2, f1*f3)
           end
end
1 Like

Many thanks