2016年11月3日木曜日

開発環境

計算機プログラムの構造と解釈[第2版](ハロルド エイブルソン (著)、ジュリー サスマン (著)、ジェラルド・ジェイ サスマン (著)、Harold Abelson (原著)、Julie Sussman (原著)、Gerald Jay Sussman (原著)、和田 英一 (翻訳)、翔泳社、原著: Structure and Interpretation of Computer Programs (MIT Electrical Engineering and Computer Science)(SICP))の第2章(データによる抽象の構築)、2.3(記号データ)、2.3.1(クォート)、問題2.53、54、55.を取り組んでみる。

その他参考書籍

問題2.53、54、55.

コード(Emacs)

(begin
  ;; (load "procedures.scm")
  (newline)
  (define (p obj) (display obj) (newline))

  (p '2.53)
  (p (list 'a 'b 'c))                   ; (a b c)
  (p (list 'george))                    ; (george)
  (p (cdr '((x1 x2) (y1 y2))))          ; ((y1 y2))
  (p (cadr '((x1 x2) (y1 y2))))         ; (y1 y2)
  (p (pair? (car '(a short list))))     ; #f
  (p (memq 'red '((red shoes) (blue socks)))) ; #f
  (p (memq 'red '(red shoes blue socks)))     ; (red shoes blue socks)

  (p '2.54)
  (define (equal? obj1 obj2)
    (if (and (pair? obj1) (pair? obj2))
        (and (equal? (car obj1) (car obj2))
             (equal? (cdr obj1) (cdr obj2)))
        (eq? obj1 obj2)))  
  (p (equal? 'a 'b))
  (p (equal? 'a 'a))
  (p (equal? '(this is a list) '(this (is a) list)))
  (p (equal? '(this is a list) '(this is a list)))

  (p '2.55)
  (p ''abracadabra)
  (p '(quote abracadabra))
  (p (quote (quote abracadabra)))
  (p (equal? ''abracadabra '(quote abracadabra)))
  (p (equal? '(quote abracadabra) (quote (quote abracadabra))))
  (p (car ''abracatabra))
  (p (car '(quote abracatabra)))
  (p (car (quote (quote abracatabra))))
  
  'done)

入出力結果(Terminal(kscheme), REPL(Read, Eval, Print, Loop))

$ ksi < sample53.scm
ksi> 
2.53
(a b c)
(george)
((y1 y2))
(y1 y2)
#f
#f
(red shoes blue socks)
2.54
#f
#t
#f
#t
2.55
(quote abracadabra)
(quote abracadabra)
(quote abracadabra)
#t
#t
quote
quote
quote
=> done
ksi> $

0 コメント:

コメントを投稿