開発環境
- macOS Sierra - Apple (OS)
- Emacs (Text Editor)
- Scheme (プログラミング言語)
- kscm(コンパイラ(ksc)・インタプリタ(ksi)、実装)
- 計算機プログラムの構造と解釈(参考書籍)
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 5(Fruitful subroutines)の Boolean functions の Exercise.を Scheme で取り組んでみる。
Boolean functions の Exercise.
コード(Emacs)
(begin (load "./lib/stdlib/base.scm") (define (is-between x y z) (<= x y z)) (define (range start end) (define (iter i result) (if (= i end) (reverse result) (iter (+ i 1) (cons i result)))) (iter start '())) (define nums (range 1 6)) (for-each (lambda (x) (for-each (lambda (y) (for-each (lambda (z) (display x) (display " <= ") (display y) (display " <= ") (display z) (display ": ") (display (is-between x y z)) (newline)) nums)) nums)) nums) 'done )
入出力結果(Terminal, REPL)
$ ./ksi < temp.scm > 1 <= 1 <= 1: #true 1 <= 1 <= 2: #true 1 <= 1 <= 3: #true 1 <= 1 <= 4: #true 1 <= 1 <= 5: #true 1 <= 2 <= 1: #false 1 <= 2 <= 2: #true 1 <= 2 <= 3: #true 1 <= 2 <= 4: #true 1 <= 2 <= 5: #true 1 <= 3 <= 1: #false 1 <= 3 <= 2: #false 1 <= 3 <= 3: #true 1 <= 3 <= 4: #true 1 <= 3 <= 5: #true 1 <= 4 <= 1: #false 1 <= 4 <= 2: #false 1 <= 4 <= 3: #false 1 <= 4 <= 4: #true 1 <= 4 <= 5: #true 1 <= 5 <= 1: #false 1 <= 5 <= 2: #false 1 <= 5 <= 3: #false 1 <= 5 <= 4: #false 1 <= 5 <= 5: #true 2 <= 1 <= 1: #false 2 <= 1 <= 2: #false 2 <= 1 <= 3: #false 2 <= 1 <= 4: #false 2 <= 1 <= 5: #false 2 <= 2 <= 1: #false 2 <= 2 <= 2: #true 2 <= 2 <= 3: #true 2 <= 2 <= 4: #true 2 <= 2 <= 5: #true 2 <= 3 <= 1: #false 2 <= 3 <= 2: #false 2 <= 3 <= 3: #true 2 <= 3 <= 4: #true 2 <= 3 <= 5: #true 2 <= 4 <= 1: #false 2 <= 4 <= 2: #false 2 <= 4 <= 3: #false 2 <= 4 <= 4: #true 2 <= 4 <= 5: #true 2 <= 5 <= 1: #false 2 <= 5 <= 2: #false 2 <= 5 <= 3: #false 2 <= 5 <= 4: #false 2 <= 5 <= 5: #true 3 <= 1 <= 1: #false 3 <= 1 <= 2: #false 3 <= 1 <= 3: #false 3 <= 1 <= 4: #false 3 <= 1 <= 5: #false 3 <= 2 <= 1: #false 3 <= 2 <= 2: #false 3 <= 2 <= 3: #false 3 <= 2 <= 4: #false 3 <= 2 <= 5: #false 3 <= 3 <= 1: #false 3 <= 3 <= 2: #false 3 <= 3 <= 3: #true 3 <= 3 <= 4: #true 3 <= 3 <= 5: #true 3 <= 4 <= 1: #false 3 <= 4 <= 2: #false 3 <= 4 <= 3: #false 3 <= 4 <= 4: #true 3 <= 4 <= 5: #true 3 <= 5 <= 1: #false 3 <= 5 <= 2: #false 3 <= 5 <= 3: #false 3 <= 5 <= 4: #false 3 <= 5 <= 5: #true 4 <= 1 <= 1: #false 4 <= 1 <= 2: #false 4 <= 1 <= 3: #false 4 <= 1 <= 4: #false 4 <= 1 <= 5: #false 4 <= 2 <= 1: #false 4 <= 2 <= 2: #false 4 <= 2 <= 3: #false 4 <= 2 <= 4: #false 4 <= 2 <= 5: #false 4 <= 3 <= 1: #false 4 <= 3 <= 2: #false 4 <= 3 <= 3: #false 4 <= 3 <= 4: #false 4 <= 3 <= 5: #false 4 <= 4 <= 1: #false 4 <= 4 <= 2: #false 4 <= 4 <= 3: #false 4 <= 4 <= 4: #true 4 <= 4 <= 5: #true 4 <= 5 <= 1: #false 4 <= 5 <= 2: #false 4 <= 5 <= 3: #false 4 <= 5 <= 4: #false 4 <= 5 <= 5: #true 5 <= 1 <= 1: #false 5 <= 1 <= 2: #false 5 <= 1 <= 3: #false 5 <= 1 <= 4: #false 5 <= 1 <= 5: #false 5 <= 2 <= 1: #false 5 <= 2 <= 2: #false 5 <= 2 <= 3: #false 5 <= 2 <= 4: #false 5 <= 2 <= 5: #false 5 <= 3 <= 1: #false 5 <= 3 <= 2: #false 5 <= 3 <= 3: #false 5 <= 3 <= 4: #false 5 <= 3 <= 5: #false 5 <= 4 <= 1: #false 5 <= 4 <= 2: #false 5 <= 4 <= 3: #false 5 <= 4 <= 4: #false 5 <= 4 <= 5: #false 5 <= 5 <= 1: #false 5 <= 5 <= 2: #false 5 <= 5 <= 3: #false 5 <= 5 <= 4: #false 5 <= 5 <= 5: #true => done > $
0 コメント:
コメントを投稿