2017年3月10日金曜日

開発環境

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
# -*- coding: utf-8 -*-

# 1.
my $r = 5;
my $volume = 4 / 3 * pi * $r ** 3;

say $volume;

# 2.
my $price = 24.95;
my $discount = 1 - 0.4;
my $shipping = 3;
my $shippings = 0.75;
my $copies = 60;

say $price * $discount * $copies + $shipping + $shippings * ($copies - 1);


# 3
my $easy = 8 * 60 + 15;
my $temp = 7 * 60 + 12;
my $total = $easy * 1 + $temp * 3 + $easy;
my $seconds = (6 * 60 + 52) * 60 + $total;

my $hours = $seconds div 60 div 60;
my $minutes = ($seconds - ($hours * 60 * 60)) div 60;

say $hours, ':', $minutes, ' 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'
> 42 = $n;
===SORRY!=== Error while compiling:
Variable '$n' is not declared
------> 42 = ⏏$n;
> $x = $y = 1;
===SORRY!=== Error while compiling:
Variable '$x' is not declared
------> <BOL>⏏$x = $y = 1;
> my $x = $y = 1;
===SORRY!=== Error while compiling:
Variable '$y' is not declared
------> my $x = ⏏$y = 1;
> my $x = my $y = 1;
1
> $x
1
> $y
1
> my ($x, $y) = 1, 1
(1 1)
> x
===SORRY!=== Error while compiling:
Undeclared routine:
    x used at line 1

> $x
1
> $y
1
> my ($z, $a) = 1, 1
(1 1)
> $z
1
> $a
1
> my $b = 1.
===SORRY!===
Decimal point must be followed by digit
------> my $b = 1.⏏<EOL>
Unsupported use of . to concatenate strings; in Perl 6 please use ~
at line 2
------> <BOL>⏏<EOL>

> my $b = 1;.
===SORRY!=== Error while compiling:
Unsupported use of . to concatenate strings; in Perl 6 please use ~
at line 2
------> <BOL>⏏<EOL>
> my $b = 1;
1
> $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
> $ ./sample1.pl
523.598775598299
945.45
7:30 am
$ 

0 コメント:

コメントを投稿

Comments on Google+: