2017年4月20日木曜日

開発環境

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 2(Variables, Expressions, and Statements)のExercises 2-1、2.を取り組んでみる。

Exercises 2-1、2.

コード(Emacs)

#!/usr/bin/env perl6

say '1.';
my $r = 5;
say 4 / 3 * pi * $r ** 3;

say '2.';
my $cover-price = 24.95;
my $discount = 40;
my $first-copy = 3;
my $copy = 0.75;

say $cover-price * (100 - $discount) / 100 * 60  + $first-copy + $copy * (60 - 1);

say '3.';
my $m = 8 + 3 * 7 + 8;
my $s = 15 + 3 * 12 + 15;

$m += $s div 60;
$s = $s % 60;

$m += 52;

my $h = 6 + $m div 60;
$m %= 60;

say "$h:$m am";

入出力結果(Terminal, REPL)

$ perl6
You may want to `zef install Readline` or `zef install Linenoise` or use rlwrap for a line editor

To exit type 'exit' or '^D'
> $n = 42
===SORRY!=== Error while compiling:
Variable '$n' is not declared
------> <BOL>⏏$n = 42
> my $n = 42
42
> $n = 42;
42
> 42 = $n;
Cannot modify an immutable Int
  in block <unit> at <unknown file> line 1

> my ($x, $y);
((Any) (Any))
> $x = $y = 1;
1
> $x;
1
> $y;
1
> $x.
===SORRY!=== Error while compiling:
Unsupported use of . to concatenate strings; in Perl 6 please use ~
at line 2
------> <BOL>⏏<EOL>
> $x .
===SORRY!=== Error while compiling:
Unsupported use of . to concatenate strings; in Perl 6 please use ~
at line 2
------> <BOL>⏏<EOL>
> $x$y
===SORRY!=== Error while compiling:
Two terms in a row
------> $x⏏$y
    expecting any of:
        infix
        infix stopper
        statement end
        statement modifier
        statement modifier loop
> $x$y;
===SORRY!=== Error while compiling:
Two terms in a row
------> $x⏏$y;
    expecting any of:
        infix
        infix stopper
        statement end
        statement modifier
        statement modifier loop
> $x * $y;
1
> Invocant requires an instance of type IO::Handle, but a type object was passed.  Did you forget a .new?

> $ ./sample2.pl
1.
523.598775598299
2.
945.45
3.
7:30 am
$

0 コメント:

コメントを投稿