2017年5月27日土曜日

開発環境

Think Perl 6: How to Think Like a Computer Scientist (Laurent Rosenfeld(著)、Allen B. Downey(著)、Oreilly & Associates Inc)のPart 1(Starting with the basics)、Chapter 11(Case Study: Data Structure Selection)の Exercise: Sets, Bags, and Mixes.を取り組んでみる。

Exercise: Sets, Bags, and Mixes.

コード(Emacs)

#!/usr/bin/env perl6
# -*- coding: utf-8 -*-

#!/usr/bin/env perl6
# -*- coding: utf-8 -*-

my $skip = True;
sub process-line (Str $line is copy) {
    # if defined index $line, "*END*THE SMALL PRINT!" {
    if defined index $line, "*** START OF THIS PROJECT GUTENBERG EBOOK EMMA ***" {
        $skip = False;
        return;
    }
    return if $skip;
    $line ~~ s:g/<[-'/]>/ /;
    $line ~~ s:g/<[;:,!?.()"_`”‘“’]>//;
    $line = $line.lc;
    return $line.words;
}
my $emma = set (process-line $_ for 'emma.txt'.IO.lines);
my $words = set 'words.txt'.IO.lines;

my $s = $emma (-) $words;

say $s.elems;
for $s.pick(10) {
    say $_;
}

入出力結果(Terminal, REPL)

$ ./sample03.pl
585
stept
dixon
puppyism
blockhead
fairbanks
ceaseless
undistinguishing
unfrequently
goddards
churchilld
$

0 コメント:

コメントを投稿