0

Surprised that Default in class ANY is frozen and without implementation???, what is the semantic for this function??

Class ANY

frozen default: detachable like Current
        -- Default value of object's type
    do
    end

My intention was to define a default: like Current or maybe detachable which returns the default value for current Class, so redefine it...

Pipo
  • 4,653
  • 38
  • 47
  • Please try to make your questions more relevant: `ANY` is not a "function", but a "class", representing *any* object. So it's not a convenience class to add features to other classes (which would in fact break those, most likely). – U. Windl May 24 '21 at 16:33

1 Answers1

1

This is a default value of a detachable version of a type. For reference types, this is Void. For expanded types, this is the corresponding default value, i.e. the one initialized with default_create. E.g., for BOOLEAN, it is False.

If an expanded class provides a specific implementation of default_create, it is used to initialize Result even without a body in default. For example, consider a class

expanded class X inherit ANY redefine default_create end feature
    item: INTEGER_32
    default_create do item := 42 end
end

For a variable x of type X, an expression x.default.item would give 42. When default is called, the value of Result is initialized by calling X.default_create that sets item. So, no instructions in the body of default are required.

To summarize, default returns

  • Void for reference types;
  • a default value for expanded types that do not redefine default_create, including basic types: False, 0, 0.0, etc. If an expanded type has nested attributes, they are initialized recursively using the same rule.
  • a value obtained by calling default_create otherwise.
Alexander Kogtenkov
  • 5,770
  • 1
  • 27
  • 35
  • Nice explanation many thx. Recomendations: point out a documentation where what you say can be read, maybe a clearer comment into ANY Class – Pipo Jun 16 '20 at 17:26