開発環境
- 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 9(Arrays and Lists)の Exercise: Implementing a Queue.を取り組んでみる。
Exercise: Implementing a Queue.
コード(Emacs)
#!/usr/bin/env perl6
# -*- coding: utf-8 -*-
sub put-in-queue(@queue, $new_item) {
unshift @queue, $new_item;
}
sub take-from-queue(@queue) {
my $item = pop @queue;
return $item;
}
my @a-queue = 1, 2, 3, 4, 5;
put-in-queue @a-queue, 0;
say @a-queue;
say take-from-queue @a-queue for 1..3;
say @a-queue;
入出力結果(Terminal, REPL)
$ ./sample1.pl [0 1 2 3 4 5] 5 4 3 [0 1 2] $
0 コメント:
コメントを投稿