計算機プログラムの構造と解釈 第二版 P84 問題2.53

とりあえず、特に難しい事はないので、書いてある通りやる。
出力の予想もあっていたので、とても嬉しい。

実装

#!/usr/local/bin/gosh
;; -*- coding: utf-8 -*-

(use ggc.debug.trace)
(use math.mt-random)


(define (memq item x)
  (cond ((null? x) faluse)
        ((eq? item (car x)) x)
        (else (memq item (cdr x)))))




;; main
(define (main args)

  (display "(list 'a 'b 'c): ")
  (display (list 'a 'b 'c))
  (newline)

  (display "(list (list 'george)): ")
  (display (list (list 'george)))
  (newline)

  (display "(cdr '((x1 x2) (y1 y2))): ")
  (display (cdr '((x1 x2) (y1 y2))))
  (newline)

  (display "(cadr '((x1 x2) (y1 y2))): ")
  (display (cadr '((x1 x2) (y1 y2))))
  (newline)

  (display "(pair? (car '(a short list))): ")
  (display (pair? (car '(a short list))))
  (newline)

  (display "(memq 'red '((red shoes) (blue socks))): ")
  (display (memq 'red '((red shoes) (blue socks))))
  (newline)

  (display "(memq 'red '(red shoes blue socks)): ")
  (display (memq 'red '(red shoes blue socks)))
  (newline)

  0)


実行

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


ん〜マンダム(古い)。