開発環境
- 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)の Exercise 5-2.を Scheme で取り組んでみる。
Exercise 5-2.
コード(Emacs)
(begin
(load "./lib/stdlib/base.scm")
(define (ack m n)
(cond ((= m 0) (+ n 1))
((and (> m 0) (= n 0)) (ack (- m 1) 1))
(#t (ack (- m 1) (ack m (- n 1))))))
(define result (ack 3 4))
(display result)
(newline)
(= result 125)
)
入出力結果(Terminal, REPL)
$ ./ksc temp && ./temp => compiled 125 => #true $
0 コメント:
コメントを投稿