<?xml version="1.0" encoding="UTF-8" ?><rdf:RDF 
  xmlns="http://purl.org/rss/1.0/"
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:atom="http://www.w3.org/2005/Atom"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xml:lang="ja">
  <channel rdf:about="http://w.atwiki.jp/meruneru/">
    <title>メモ帳</title>
    <link>http://w.atwiki.jp/meruneru/</link>
    <atom:link href="https://w.atwiki.jp/meruneru/rss10.xml" rel="self" type="application/rss+xml" />
    <atom:link rel="hub" href="https://pubsubhubbub.appspot.com" />
    <description>メモ帳</description>

    <dc:language>ja</dc:language>
    <dc:date>2013-02-25T18:48:56+09:00</dc:date>
    <utime>1361785736</utime>

    <items>
      <rdf:Seq>
                <rdf:li rdf:resource="https://w.atwiki.jp/meruneru/pages/28.html" />
                <rdf:li rdf:resource="https://w.atwiki.jp/meruneru/pages/27.html" />
                <rdf:li rdf:resource="https://w.atwiki.jp/meruneru/pages/26.html" />
                <rdf:li rdf:resource="https://w.atwiki.jp/meruneru/pages/25.html" />
                <rdf:li rdf:resource="https://w.atwiki.jp/meruneru/pages/24.html" />
                <rdf:li rdf:resource="https://w.atwiki.jp/meruneru/pages/23.html" />
                <rdf:li rdf:resource="https://w.atwiki.jp/meruneru/pages/22.html" />
                <rdf:li rdf:resource="https://w.atwiki.jp/meruneru/pages/21.html" />
                <rdf:li rdf:resource="https://w.atwiki.jp/meruneru/pages/2.html" />
                <rdf:li rdf:resource="https://w.atwiki.jp/meruneru/pages/17.html" />
              </rdf:Seq>
    </items>
	
		
    
  </channel>
    <item rdf:about="https://w.atwiki.jp/meruneru/pages/28.html">
    <title>Int NotifyApp_startup()</title>
    <link>https://w.atwiki.jp/meruneru/pages/28.html</link>
    <description>
      Int NotifyApp_startup(String mapFile)

*機能
Function to execute the startup for NotifyApp sample application

*引数
-String mapFile

*戻り値
-Int

*参照
-[[void NotifyApp_callback()]]
-[[Int SysLinkSamples_setToRunProcIds()]]  common/SysLinkSamples.c内で定義
-[[Bool SysLinkSamples_toRunProcId()]]  common/SysLinkSamples.c内で定義
-[[SlaveLoader_startup()]]              slaveLoader/slaveLoader.c

*大域変数
**ProcMgr_BootMode  NotifyApp_bootMode = ProcMgr_BootMode_Boot;
ProcMgr_BootModeは列挙型。ブートの種類を格納している。
#highlight(c){
00241 typedef enum {
00242     ProcMgr_BootMode_Boot           = 0u,
00244     ProcMgr_BootMode_NoLoad_Pwr     = 1u,
00247     ProcMgr_BootMode_NoLoad_NoPwr   = 2u,
00251     ProcMgr_BootMode_NoBoot         = 3u,
00255     ProcMgr_BootMode_EndValue       = 4u
00257 } ProcMgr_BootMode ;
}

*実装

*詳細
**SlaveLoader_startup    </description>
    <dc:date>2013-02-25T18:48:56+09:00</dc:date>
    <utime>1361785736</utime>
  </item>
    <item rdf:about="https://w.atwiki.jp/meruneru/pages/27.html">
    <title>Void NotifyApp_callback()</title>
    <link>https://w.atwiki.jp/meruneru/pages/27.html</link>
    <description>
      *機能
プロセスからイベントを受け取った時に呼び出される処理を記述する関数。

*引数
-UInt16       procId,　イベントを受け取ったプロセスのID
-UInt16       lineId,　
-UInt32       eventNo,　受け取ったイベント番号
-Void *       arg,　　　イベント番号に関連する引数
-UInt32       payload　　イベント一緒に受け取ったデータ

*戻り値
-void

*参照
-[[void NotifyApp_execute()]]

*大域変数
**UInt32 　SysLogging_UserCallbackCount=0

**UInt32 NotifyApp_recvEventCount [MultiProc_MAXPROCESSORS] [NOTIFYAPP_NUMEVENTS];
イベント事、プロセス毎に受け取ったイベントをカウントする配列。

*実装
#highlight(c){
    if ((eventCount % NOTIFY_PRINT_COUNT) == 0) {
        Osal_printf (&quot;Received %d events for event ID %d &quot;
                     &quot;from processor %d\n&quot;,
                     eventCount,
                     eventNo,
                     procId);
    }
}
どのプロセスからそのイベントを何回受け取ったかを表示している。
eventCountは局所変数であり、NotifyApp_recvEventCount[procId][eventNo - NOTIFYAPP_EVENT_NO]が入っている。
この後にif分岐でエラーになるかのチェックを行なっている。
その際にMultiProc_getNumProcessors()が利用されている。

*詳細
**UInt16 MultiProc_getNumProcessors (Void)
マルチプロセッサで動作しているプロセス数を返す。    </description>
    <dc:date>2013-02-25T18:10:51+09:00</dc:date>
    <utime>1361783451</utime>
  </item>
    <item rdf:about="https://w.atwiki.jp/meruneru/pages/26.html">
    <title>Void NotifyApp_rtosInfocallback()</title>
    <link>https://w.atwiki.jp/meruneru/pages/26.html</link>
    <description>
      *機能
RTOS側の情報を出力する関数。

*引数
-UInt16       procId,
-UInt16       lineId,
-UInt32       eventNo,
-Void *       arg,
-UInt32       payload

*戻り値
-void

*実装
#highlight(c){
    Void NotifyApp_rtosInfocallback (UInt16       procId,
                                UInt16       lineId,
                                UInt32       eventNo,
                                Void *       arg,
                                UInt32       payload){
        Osal_printf (&quot;Number of RTOS-side received/sent events:\n&quot;
                 &quot;    procId: [%d]\n&quot;
                 &quot;    Number of events: [%d]\n&quot;,
                 procId,
                 payload);
        if (payload != (NOTIFYAPP_NUMEVENTS * NOTIFYAPP_NUM_TRANSFERS)) {
            Osal_printf (&quot;*****Failure on RTOS-side*****\n&quot;
                     &quot;    Expected num events: [%d]\n&quot;
                     &quot;    Received num events: [%d]\n&quot;,
                     (NOTIFYAPP_NUMEVENTS * NOTIFYAPP_NUM_TRANSFERS),
                     payload);
        }
        OsalSemaphore_post ((OsalSemaphore_Handle) arg);
    }
}

*詳細
**void Osal_printf(char*)
#include &lt;ti/syslink/utils/OsalPrint.h&gt;　
で利用可能。prinfと同じ


**typedef 　struct OsalSemaphore_Object* 　OsalSemaphore_Handle
struct OsalSemaphore_Object*はプログラマには見えない。

**Int OsalSemaphore_post (OsalSemaphore_Handle semHandle)
この関数により、セマフォを開放できる。よって他のプロセスがセマフォを利用できるようになる。

#highlight(c){
209 /* Creates the semaphore object. */
210 OsalSemaphore_Handle OsalSemaphore_create (UInt32 semType);
211 
212 /* Deletes the semaphore object */
213 Int OsalSemaphore_delete (OsalSemaphore_Handle * semHandle);
214 
215 /* Wait on the said Semaphore in the kernel thread context */
216 Int OsalSemaphore_pend (OsalSemaphore_Handle semHandle, UInt32 timeout);
217 
218 /* Signal the semaphore and make it available for other threads. */
219 Int OsalSemaphore_post (OsalSemaphore_Handle semHandle);
}    </description>
    <dc:date>2013-02-25T17:58:15+09:00</dc:date>
    <utime>1361782695</utime>
  </item>
    <item rdf:about="https://w.atwiki.jp/meruneru/pages/25.html">
    <title>NotifyApp.c</title>
    <link>https://w.atwiki.jp/meruneru/pages/25.html</link>
    <description>
      NotifyApp.c

-[[Void NotifyApp_rtosInfocallback()]]
-[[Void NotifyApp_callback()]]
-[[Int NotifyApp_startup()]]
-[[Int NotifyApp_execute()]]
-[[Int NotifyApp_shutdown()]]    </description>
    <dc:date>2013-02-25T16:57:24+09:00</dc:date>
    <utime>1361779044</utime>
  </item>
    <item rdf:about="https://w.atwiki.jp/meruneru/pages/24.html">
    <title>knl</title>
    <link>https://w.atwiki.jp/meruneru/pages/24.html</link>
    <description>
      syslink_2_00_02_80/packages/ti/syslink/samples/hlos/notify/knl

-[[Linux/Makefile]]
-[[Linux/NotifyAppDrv.c]]    </description>
    <dc:date>2013-02-25T16:52:16+09:00</dc:date>
    <utime>1361778736</utime>
  </item>
    <item rdf:about="https://w.atwiki.jp/meruneru/pages/23.html">
    <title>usr</title>
    <link>https://w.atwiki.jp/meruneru/pages/23.html</link>
    <description>
      syslink_2_00_02_80/packages/ti/syslink/samples/hlos/notify/usr

-[[Linux/Makefile]]
-[[Linux/NotifyAppOS.c]]    </description>
    <dc:date>2013-02-25T16:51:07+09:00</dc:date>
    <utime>1361778667</utime>
  </item>
    <item rdf:about="https://w.atwiki.jp/meruneru/pages/22.html">
    <title>Notify</title>
    <link>https://w.atwiki.jp/meruneru/pages/22.html</link>
    <description>
      syslink_2_00_02_80/packages/ti/syslink/samples/hlos/notify/

-[[NotifyApp.c]]
-[[NotifyApp.h]]
-[[knl]]
-[[usr]]    </description>
    <dc:date>2013-02-25T16:50:00+09:00</dc:date>
    <utime>1361778600</utime>
  </item>
    <item rdf:about="https://w.atwiki.jp/meruneru/pages/21.html">
    <title>TI</title>
    <link>https://w.atwiki.jp/meruneru/pages/21.html</link>
    <description>
      syslink_2_00_02_80/packages/ti/syslink/samples/hlos/
以下にあるディレクトリ群


-[[common]]

-[[gateMP]]

-[[heapMemMP]]

-[[listMP]]

-[[notify]]

-[[ringIO_gpp]]

-[[slaveLoader]]

-[[frameq]]

-[[heapBufMP]]

-[[knlNotify]]

-[[messageQ]]

-[[ringIO]]

-[[sharedRegion]]

-[[tilerDaemon]]    </description>
    <dc:date>2013-02-25T16:49:49+09:00</dc:date>
    <utime>1361778589</utime>
  </item>
    <item rdf:about="https://w.atwiki.jp/meruneru/pages/2.html">
    <title>メニュー</title>
    <link>https://w.atwiki.jp/meruneru/pages/2.html</link>
    <description>
      **メニュー
-[[トップページ]]
-[[プラグイン紹介&gt;プラグイン]]
-[[まとめサイト作成支援ツール]]
-[[メニュー]]
-[[メニュー2]]

----
**コンテンツ
-[[SICP]]
-[[Schme デバッグ]]
-[[応用情報技術者]]
-[[TI]]
**リンク
-[[@wiki&gt;&gt;http://atwiki.jp]]
-[[@wikiご利用ガイド&gt;&gt;http://atwiki.jp/guide/]]

**他のサービス
-[[無料ホームページ作成&gt;&gt;http://atpages.jp]]
-[[無料ブログ作成&gt;&gt;http://atword.jp]]
-[[2ch型掲示板レンタル&gt;&gt;http://atchs.jp]]
-[[無料掲示板レンタル&gt;&gt;http://atbbs.jp]]
-[[お絵かきレンタル&gt;&gt;http://atpaint.jp/]]
-[[無料ソーシャルプロフ&gt;&gt;http://sns.atfb.jp/]]

// リンクを張るには &quot;[&quot; 2つで文字列を括ります。
// &quot;&gt;&quot; の左側に文字、右側にURLを記述するとリンクになります


//**更新履歴
//#recent(20)

&amp;link_editmenu(text=ここを編集)    </description>
    <dc:date>2013-02-25T16:35:45+09:00</dc:date>
    <utime>1361777745</utime>
  </item>
    <item rdf:about="https://w.atwiki.jp/meruneru/pages/17.html">
    <title>SICP 2章</title>
    <link>https://w.atwiki.jp/meruneru/pages/17.html</link>
    <description>
      *ex 2.7 &amp; 2.8
区間算術演算…難しめ。後回し。
#highlight(lisp){
(define (make-interval a b) (cons a b))
(define (upper-bound x) (max (car x) (cdr x)))
(define (lower-bound x) (min (car x) (cdr x)))

(define (add-interval x y)
  (make-interval (+ (lower-bound x) (lower-bound y))
                 (+ (upper-bound x) (upper-bound y))))
(define (sub-interval x y)
  (make-interval (- (lower-bound x) (lower-bound y))
                 (- (upper-bound x) (upper-bound y))))
(define (mul-interval x y)
  (let ((p1 (* (lower-bound x) (lower-bound y)))
        (p2 (* (lower-bound x) (upper-bound y)))
        (p3 (* (upper-bound x) (lower-bound y)))
        (p4 (* (upper-bound x) (upper-bound y))))
    (make-interval (min p1 p2 p3 p4)
                   (max p1 p2 p3 p4))))

(define (div-interval x y)
  (mul-interval x 
                (make-interval (/ 1.0 (upper-bound y))
                               (/ 1.0 (lower-bound y)))))
}

*ex 2.17
listの最後の要素を返す。ただし空ではないlistが与えられる。
#highlight(lisp){
(define (last-pair ls) 
  (if (null? (cdr ls)) 
    (car ls) 
    (last-pair (cdr ls))))
}
*ex 2.18
listの要素を逆順にする。
#highlight(lisp){
(define (myreverse ls)
  (define (iter list result)
     (if (null? list)
	result
	(iter (cdr list) (cons (car list) result))))
  (iter ls &#039;()))
}
*ex 2.21
listの各要素を2乗したlistを返す。別々の方法で2つ定義する。
#highlight(lisp){
(define (square-list ls)
  (if (null? ls) 
    &#039;()
    (cons (* (car ls) (car ls)) (square-list (cdr ls)))))
}
#highlight(lisp){
(define (square-list ls) 
  (map (lambda (x) (* x x)) ls))
}
#highlight(lisp){
gosh&gt; (square-list &#039;(1 2 3))
(1 4 9)
}
*ex 2.23
for-eachを自分で実装する。
for-eachは手続きとlistを受け取り、格要素に手続きを適用後、
その要素を返す。(listは返さない)
#highlight(lisp){
(define (for-each proc ls)
  (if (null? ls) 
  #t
  (begin (display (proc (car ls)))
    (newline)
    (for-each proc (cdr ls)))))
}
#highlight(lisp){
gosh&gt; (for-each (lambda (x) (+ x x)) &#039;(1 2 3))
2
4
6
#t
}
*ex 2.25
listから7を取り出す。car cdrは省略形が用意されてるけど4つまで。
#highlight(lisp){
gosh&gt; (car (cdaddr &#039;(1 3 (5 7) 9)))
7
gosh&gt; (caar  &#039;((7)))
7
gosh&gt; (cadadr (cadadr (cadadr &#039;(1 (2 (3 (4 (5 (6 7)))))))))
7
}

*ex 2.26
append cons list の違いについて。
#highlight(lisp){
gosh&gt; (define x &#039;(1 2 3))
x
gosh&gt; (define y &#039;(4 5 6))
y
gosh&gt; (append x y)
(1 2 3 4 5 6)
gosh&gt; (cons x y)
((1 2 3) 4 5 6)
gosh&gt; (list x y)
((1 2 3) (4 5 6))
}

*ex 2.27
ex 2.17の応用版。ネストのあるlistでも、要素を逆順にする。
#highlight(lisp){
(define (deep-reverse ls)
  (define (iter list result)
     (cond ((null? list) result)
           ((not (pair? (car list))) 
　　　　　　　(iter (cdr list) (cons (car list) result)))　;残りのlistがpairではない
           (else 
　　　　　　　(iter (cdr list) (cons (iter (car list) &#039;()) result))))) ;残りのlistがまだpair
  (iter ls &#039;()))
}
#highlight(lisp){
gosh&gt; (deep-reverse &#039;((1 2 ) (4 5)))
((5 4) (2 1))
}

*ex 2.28
引数に木(list)をとり、左の葉を順に並べたlistを返す。
#highlight(lisp){
(define (fringe ls)
  (define (iter lst result)
     (cond ((null? lst) result)
           ((not (pair? (car lst))) (iter (cdr lst) (append result (list (car lst)))))
           (else (iter (cdr lst) (iter (car lst) result)))))
  (iter ls &#039;()))
}
#highlight(lisp){
gosh&gt; (define x (list (list 1 2) (list 3 4)))
x
gosh&gt; (fringe x)
(1 2 3 4)
}

*ex 2.29
2進モービル。難しいから放棄した。

left right structure は数値かlist,lengthは数値
#highlight(lisp){
(define (make-mobile left right) (list left right))
(define (make-branch length structure) (list length structure))

;a
(define (left-branch mobile) (car mobile))
(define (right-branch mobile) (cadr mobile))
(define (branch-length brnc) (car brnc))
(define (branch-structure brnc) (cadr brnc))
}
*ex 2.30
ex2.21の応用版。treeの葉に対して、それぞれ2乗し、演算後の木を返す。
#highlight(lisp){
(define (square x) (* x x))
(define (square-tree ls)
  (map (lambda (sub-ls)
    (if (pair? sub-ls)
      (square-tree sub-ls)
      (square sub-ls))) ls))
}
#highlight(lisp){
gosh&gt; (square-tree &#039;(1 2 3 (4 5)))
(1 4 9 (16 25))
}
*ex 2.31
ex2.30の解答を抽象化する。(tree-map square tree)とすれば、square-treeと同じ機能を果たすようにする。
#highlight(lisp){
(define (square x) (* x x))
(define (square-tree tree)
  (tree-map square tree))

(define (tree-map proc tree)
  (let loop ((src tree) (dst &#039;()))
    (cond ((null? src) (reverse dst))
          ((pair? (car src))
             (loop (cdr src) (cons (tree-map proc (car src)) dst)))
          (else 
             (loop (cdr src) (cons (proc (car src)) dst))))))
}
*ex 2.33
公認インタフェースの穴埋め問題。
#highlight(lisp){
(define (accumulate op initial sequence)
  (if (null? sequence)
      initial
      (op (car sequence)
          (accumulate op initial (cdr sequence)))))
(define (map p sequence)
 (accumulate (lambda (x y) (cons (p x) y)) &#039;() sequence))
(define (append seq1 seq2) 
 (accumulate cons seq2 seq1))
(define (length sequence)
  (accumulate (lambda (x y) (+ 1 y)) 0 sequence))
}
#highlight(lisp){
gosh&gt; (map (lambda (x) (* x x)) &#039;(1 2 3))
(1 4 9)
gosh&gt; (append &#039;(1 2 3) &#039;(4 (5) 6))
(1 2 3 4 (5) 6)
gosh&gt; (length &#039;(1 2 3))
3
}
*ex 2.34
Hornerの方法。
#highlight(lisp){
(define (accumulate op initial sequence)
  (if (null? sequence)
      initial
      (op (car sequence)
          (accumulate op initial (cdr sequence)))))
(define (horner-eval x coefficient-sequence)
  (accumulate (lambda (this-coeff higher-terms) 
                (+ this-coeff (* x higher-terms)))
              0
              coefficient-sequence))
}
$$x=2$$のとき、$$1+3x+5x^3+x^5$$の値を求めてみると、
#highlight(lisp){
gosh&gt; (horner-eval 2 (list 1 3 0 5 0 1))
79
}
*ex 2.35
2.2.2節のcount-leavesの公認インタフェース版
#highlight(lisp){
(define (accumulate op initial sequence)
  (if (null? sequence)
      initial
      (op (car sequence)
          (accumulate op initial (cdr sequence)))))
(define (count-leaves t)
  (accumulate + 0 (map (lambda (x) 
                           (cond ((null? x) 0)
                                   ((not (pair? x)) 1)
                                    (else (count-leaves x)))) t)))
(define (map p sequence)
 (accumulate (lambda (x y) (cons (p x) y)) &#039;() sequence)) 
}
*ex 2.36
#highlight(lisp){
(define (accumulate op initial sequence)
  (if (null? sequence)
      initial
      (op (car sequence)
          (accumulate op initial (cdr sequence)))))
(define (accumulate-n op init seqs)
  (if (null? (car seqs))
      &#039;()
      (cons (accumulate op init (map car seqs))
            (accumulate-n op init (map cdr seqs)))))
(define (map p sequence)
 (accumulate (lambda (x y) (cons (p x) y)) &#039;() sequence))
}
#highlight(lisp){
gosh&gt; (accumulate-n + 0 &#039;((1 2 3) (4 5 6) (7 8 9) (10 11 12)))
(22 26 30)
}
*ex 2.37
行列計算。accumulate-nの便利さ。要確認
#highlight(lisp){
(define (accumulate op initial sequence)
  (if (null? sequence)
      initial
      (op (car sequence)
          (accumulate op initial (cdr sequence)))))
(define (accumulate-n op init seqs)
  (if (null? (car seqs))
      &#039;()
      (cons (accumulate op init (map car seqs))
            (accumulate-n op init (map cdr seqs)))))
(define (dot-product v w)
  (accumulate + 0 (map * v w)))
(define (matrix-*-vector m v)
  (map (lambda (x) (dot-product x v)) m))
(define (transpose mat)
  (accumulate-n cons &#039;() mat))
(define (matrix-*-matrix m n)
  (let ((cols (transpose n)))
    (map (lambda (x) (matrix-*-vector cols x)) m)))
}
*写像の入れ子
#highlight(lisp){
gosh&gt; (map (lambda (i) (enumerate-interval 1 (- i 1))) (enumerate-interval 1 6))
(() (1) (1 2) (1 2 3) (1 2 3 4) (1 2 3 4 5))
}
より、
#highlight(lisp){
gosh&gt; (accumulate append 
            &#039;()
             (map (lambda (i) 
                        (map (lambda (j) (list i j))  
                            (enumerate-interval 1 (- i 1))))
                  (enumerate-interval 1 6)))                   

((2 1) (3 1) (3 2) (4 1) (4 2) (4 3) (5 1) (5 2) (5 3) (5 4) (6 1) (6 2) (6 3) (
6 4) (6 5))
}
素数判定は、
#highlight(lisp){
(define (prime? n)
  (define (smallest-divisor n)
    (find-divisor n 2))
  (define (square x) (* x x))
  (define (find-divisor n test-divisor)
    (cond ((&gt; (square test-divisor) n) n)
        ((divides? test-divisor n) test-divisor)
        (else (find-divisor n (+ test-divisor 1)))))
  (define (divides? a b)
    (= (remainder b a) 0))
  (= n (smallest-divisor n)))
}
したがって、
#highlight(lisp){
(define (filter predicate sequence)
  (cond ((null? sequence) &#039;())
        ((predicate (car sequence))
         (cons (car sequence)
               (filter predicate (cdr sequence))))
        (else (filter predicate (cdr sequence)))))
(define (flatmap proc seq)
  (accumulate append &#039;() (map proc seq)))
(define (prime-sum? pair)
  (prime? (+ (car pair) (cadr pair))))
(define (make-pair-sum pair)
  (list (car pair) (cadr pair) (+ (car pair) (cadr pair))))
(define (prime-sum-pairs n)
  (map make-pair-sum
       (filter prime-sum?
               (flatmap
                (lambda (i)
                  (map (lambda (j) (list i j))
                       (enumerate-interval 1 (- i 1))))
                (enumerate-interval 1 n)))))
}
信号処理のような流れが大切。この写像の入り子を利用することで、多重ループで演算するような計算ができる。
*ex 2.44
#highlight(lisp){
(define (right-split painter n)
  (if (= n 0)
      painter
      (let ((smaller (right-split painter (- n 1))))
        (beside painter (below smaller smaller)))))
}
では、元の画像を半分に縮めたものを上下にして横にならべられる。
 (beside painter (below smaller smaller))
という処理を行っているためであるから、ここを
&quot;元の画像を半分に縮めたものを左右にして上にならべる&quot;とすればよい。
#highlight(lisp){
(define (left-split painter n)
  (if (= n 0)
      painter
      (let ((smaller (left-split painter (- n 1))))
        (below painter (beside smaller smaller)))))
}
*ex 2.56
微分演算。
#highlight(lisp){
;The variables are symbols. They are identified by the primitive predicate symbol?:
(define (variable? x) (symbol? x))
;Two variables are the same if the symbols representing them are eq?:
(define (same-variable? v1 v2)
  (and (variable? v1) (variable? v2) (eq? v1 v2)))
;Sums and products are constructed as lists:
(define (make-sum a1 a2)
  (cond ((=number? a1 0) a2)
        ((=number? a2 0) a1)
        ((and (number? a1) (number? a2)) (+ a1 a2))
        (else (list &#039;+ a1 a2))))
;This uses the procedure =number?, which checks whether an expression is equal to a given number:
(define (=number? exp num)
  (and (number? exp) (= exp num)))
(define (make-product m1 m2)
  (cond ((or (=number? m1 0) (=number? m2 0)) 0)
        ((=number? m1 1) m2)
        ((=number? m2 1) m1)
        ((and (number? m1) (number? m2)) (* m1 m2))
        (else (list &#039;* m1 m2))))
;A sum is a list whose first element is the symbol +:
(define (sum? x)
  (and (pair? x) (eq? (car x) &#039;+)))
;The addend is the second item of the sum list:
(define (addend s) (cadr s))
;The augend is the third item of the sum list:
(define (augend s) (caddr s))
;A product is a list whose first element is the symbol *:
(define (product? x)
  (and (pair? x) (eq? (car x) &#039;*)))
;The multiplier is the second item of the product list:
(define (multiplier p) (cadr p))
;The multiplicand is the third item of the product list:
(define (multiplicand p) (caddr p))
;;改良版
(define (deriv exp var)
  (cond ((number? exp) 0)
        ((variable? exp)
         (if (same-variable? exp var) 1 0))
        ((sum? exp)
         (make-sum (deriv (addend exp) var)
                   (deriv (augend exp) var)))
        ((product? exp)
         (make-sum
           (make-product (multiplier exp)
                         (deriv (multiplicand exp) var))
           (make-product (deriv (multiplier exp) var)
                         (multiplicand exp))))
        ((exponentiation? exp)
         (let ((n (exponent exp)))
           (cond ((= n 0) 1)
                 ((= n 1) n)
                 (else
                  (make-product n
	                        (make-exponentiation (base exp) (- n 1)))))))
        (else
         (error &quot;unknown expression type -- DERIV&quot; exp))))
}
*ex 2.59
#highlight(lisp){
(define true #t)
(define false #f)
(define (element-of-set? x set)
  (cond ((null? set) false)
        ((equal? x (car set)) true)
        (else (element-of-set? x (cdr set)))))
(define (adjoin-set x set)
  (if (element-of-set? x set)
      set
      (cons x set)))
(define (intersection-set set1 set2)
  (cond ((or (null? set1) (null? set2)) &#039;())
        ((element-of-set? (car set1) set2)        
         (cons (car set1)
               (intersection-set (cdr set1) set2)))
        (else (intersection-set (cdr set1) set2))))
(define (union-set set1 set2)
 (let loop ((ans &#039;())
            (src (append set1 set2)))
  (cond ((null? src) (reverse ans))
        ((element-of-set? (car src) ans)        
         (loop ans (cdr src)))
        (else 
          (loop (cons (car src) ans) (cdr src))))))

gosh&gt; (union-set &#039;(1 2 3) &#039;(2 4 5))
(1 2 3 4 5)
}
*ex 2.61
#highlight(lisp){
(define (adjoin-set x set)
  (cond ((null? set) (cons x &#039;()))
        ((= x (car set)) ;;重複ok
          (cons x set))
        ((&lt; x (car set))
          (cons x set))
         (else
          (cons (car set) (adjoin-set x (cdr set))))))
}    </description>
    <dc:date>2012-09-03T17:59:25+09:00</dc:date>
    <utime>1346662765</utime>
  </item>
  </rdf:RDF>
