New Protocol

Run Settings
LanguageRaku
Language Version
Run Command
use Protocol; protocol FormattableKeysProtocol { method keys { ... } method formatted-keys { $.keys.join: ", " } } constant FormattableKeys = FormattableKeysProtocol.coerce; my FormattableKeys $a = %( a => 1, b => 2 ); say $a; say $a.formatted-keys; multi sub a(FormattableKeys $a) { say $a + 1; say $a.formatted-keys; say $a.^name } a %(x => 1, y => 2, z => 3);
my package EXPORTHOW { package DECLARE { use MetamodelX::Protocol; constant protocol = MetamodelX::Protocol; } }
unit class MetamodelX::Protocol is Metamodel::ClassHOW; has @.yada; role ParentRole[$parent] { ::?CLASS.^add_parent: $parent } role Protocolable { multi method COERCE(Any \value where { .^methods>>.name.any ~~ $.HOW.yada.all }) { my $parent = self.WHAT; my \child = value but ParentRole[$parent]; child } method coerce { my @yada = $.HOW.yada; my subset Protocol of Any where { .^methods>>.name.any ~~ @yada.all }; my constant SELF = ::?CLASS; SELF(Protocol) } } method new_type(:$name = "<anon>") { my $target_type := callsame; $target_type.^add_role: Protocolable; $target_type } multi method add_method(Mu, $name, & where { .yada }) { @!yada.push: $name } multi method add_method(|c) { nextsame }
Editor Settings
Theme
Key bindings
Full width
Lines