Hi,
I stumbled over a discussion between Raku developers on
"Raku/proplem-solving" issue 227 "Coercion reconsidered and unified" and
I saw something interesting about coercion. Without much knowledge I
started to experiment with a method called COERCE(). This ended
successful and can now write, for example, something like
my Gnome::Gdk3::Visual() $visual = $button.get-visual;
which feels more natural instead of
my Gnome::dtk3::Visual $visual .= new(:native-object($button.get-visual));
I can also restrict the coercion like so,
my Gnome::Gdk3::Visual(N-GObject) $visual = …;
The .get-visual() example returns a native object which must be
encapsulated into the Visual type to access the Visual methods. In the
Gnome::* libraries are many such calls returning native structures which
needs to be handled like above to be able to do something with it.
The question now is that I can't find anything about COERCE in the
documentation. Although I have checked the Raku source code and have
seen that it is used there, I wonder if this is still experimental Raku
code and subject to changes.
Regards,
Marcel