14. Программа с эмотиконами для самостоятельного разбора

Сегодня вашему вниманию предлагается программа на Perl 6 для самостоятельного изучения.

class 人 {
    has $.name;
    has $.sex;
    has $.phone is rw;
    
    method gist {
        "$.sex $.name"
    }
}

sub prefix:<👨>($name) {
    人.new(name => $name, sex => '👨')
}

sub prefix:<👩>($name) {
    人.new(name => $name, sex => '👩')
}

sub infix:<☎️>(人 $人 is rw, $phone) {
    $人.phone = $phone;
}

sub prefix:<📲>(人 $人) {
    print "Звоним +{$人.phone}";
    for 1..5 {
        sleep ½;
        '.'.print;
    }
    say "\n— Алло, {$人.name}?";
}

sub prefix:<🔊>(人 $人) {
    $人.say
}

my $X = 👨'Иван Петров';
my $Y = 👩'Лиза Смирнова';

$X ☎️ +79031234567;

🔊$X;
🔊$Y;

📲 $X;

Запускаем программу:

class-emoticons (1)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s