2017年5月6日土曜日

開発環境

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 7(Strings)の Exercise 7-2 にミスがあるっぽいから報告、提出してみた。

Exercise 7-2.(No. 2809)

#!/usr/bin/env perl6

sub is-lower(Str $input) {
    return so $char ~~ /^<[a..z]>$/;
}
ではなく、
#!/usr/bin/env perl6

sub is-lower(Str $input) {
    return so $input ~~ /^<[a..z]>$/;
}

# or

sub is-lower(Str $char) {
    return so $char ~~ /^<[a..z]>$/;
}

確認。

コード(Emacs)

sample_errata.pl

#!/usr/bin/env perl6

sub is-lower(Str $input) {
    return so $char ~~ /^<[a..z]>$/;
}

sample_errata1.pl

#!/usr/bin/env perl6

sub is-lower1(Str $input) {
    return so $input ~~ /^<[a..z]>$/;
}

sub is-lower2(Str $char) {
    return so $char ~~ /^<[a..z]>$/;
}

say is-lower1('a');
say is-lower2('a');

say is-lower1('A');
say is-lower2('A');

入出力結果(Terminal)

$ ./sample_errata.pl
===SORRY!=== Error while compiling /Users/kamimura/Documents/perl6/think_perl6/ch7/./sample_errata.pl
Variable '$char' is not declared. Did you mean any of these?
    &chars
    &chr

at /Users/kamimura/Documents/perl6/think_perl6/ch7/./sample_errata.pl:4
------>     return so ⏏$char ~~ /^<[a..z]>$/;
$ ./sample_errata1.pl
True
True
False
False
$

0 コメント:

コメントを投稿