開発環境
- macOS Sierra - Apple (OS)
- Emacs (Text Editor)
- Perl 6 (プログラミング言語)
- Rakudo(コンパイラ、実装)
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 1(The way of the program)のExercises 1-1、2.を取り組んでみる。
Exercises 1-1、2.
コード(Emacs)
#!/usr/bin/env perl6 # -*- coding: utf-8 -*- say '1.'; say 42 * 60 * 42; say '2.'; say 10 / 1.61; say '3.'; say 10 / (42 * 60 + 42); say (10 / 1.61) / (42 * 60 + 42); say (10 / 1.61) / ((42 * 60 + 42) / 60); say (10 / 1.61) / ((42 * 60 + 42) / 60 / 60);
入出力結果(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'
> say 'perl6';
perl6
> say perl6';
===SORRY!=== Error while compiling:
Two terms in a row
------> say perl6⏏';
expecting any of:
infix
infix stopper
postfix
statement end
statement modifier
statement modifier loop
> say 'perl6;
*
* C-c C-c
$ 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'
> -2
-2
> 2++2
===SORRY!=== Error while compiling:
Two terms in a row
------> 2++⏏2
expecting any of:
infix
infix stopper
statement end
statement modifier
statement modifier loop
> 2+2
4
> 2+-2
0
> 02
Potential difficulties:
Leading 0 does not indicate octal in Perl 6. Please use 0o2 if you mean that.
------> 02⏏<EOL>
2
> 0o2
2
> 0o16
14
> 2 2;
===SORRY!=== Error while compiling:
Two terms in a row
------> 2⏏ 2;
expecting any of:
infix
infix stopper
statement end
statement modifier
statement modifier loop
> 2, 2;
(2 2)
> Invocant requires an instance of type IO::Handle, but a type object was passed. Did you forget a .new?
> $ ./sample1.pl
1.
105840
2.
6.211180
3.
0.003903
0.0024243
0.145461
8.727654
$
0 コメント:
コメントを投稿