symbol symbol symbol Hello true symbol Hello Hallo
symbol=? の意味 • symbolの比較演算子 (symbol=? 'Hello) → true (symbol=? 'Hello 'Hallo) → false 20
Dr. Scheme の使用 • Dr. Scheme の起動 プログラム → PLT Scheme → Dr. Scheme • 今日の演習では「Intermediate Student」 に設定 Language → Choose Language → Intermediate Student → Execute ボタン 28
入力と出力 (list 15 8 6 32 23) 6 element 3 入力 出力 51
(element 3 (list 15 8 6 32 23)) から6が得られる過程 (element 3 (list 15 8 6 32 23)) 最初の式 = (first (rest (list 15 8 6 32 23)))) (first (rest a-list))) = (first (rest (list 8 6 32 23))) = (first (list 6 32 23)) =6 に a-list = (list 15 8 6 32 23) が 代入される (rest (list 15 8 6 32 23)) → (list 8 6 32 23) (rest (list 8 6 32 23)) → (list 6 32 23) コンピュータ内部での計算 実行結果 53
(element 3 (list 15 8 6 32 23)) から6が得られる過程 (element 3 (list 15 8 6 32 23)) = (first (rest (list 15 8 6 32 23)))) = (first (rest (list 8 6 32 23))) これは, (define (element 3 a-list) = (first (list 6 32 23)) (first (rest a-list)))) = 6 の a-list を (list 15 8 6 32 23) で置き換えたも の 54
「例題8.シンボル」の手順 1. 次を「定義用ウインドウ」で,実行しなさい • 入力した後に,Execute ボタンを押す ; ; reply: symbol -> symbol ; ; to determine a reply for the greeting s (define (reply s) (cond [(symbol=? 'Good. Morning s) 'Hi] [(symbol=? 'How. Are. You s) 'Fine] [(symbol=? 'Good. Afternoon s) 'Need. ANap] [(symbol=? 'Good. Evening s) 'Boy. Am. ITired])) 2. その後,次を「実行用ウインドウ」で実行しなさい (reply 'Good. Morning) (reply 'Hello) ☆ 次は,課題に進んでください 71
reply 関数 ; ; reply: symbol -> symbol ; ; to determine a reply for the greeting s (define (reply s) (cond [(symbol=? 'Good. Morning s) 'Hi] [(symbol=? 'How. Are. You s) 'Fine] [(symbol=? 'Good. Afternoon s) 'Need. ANap] [(symbol=? 'Good. Evening s) 'Boy. Am. ITired])) 76
(reply 'Good. Morning) から 'Hi が得られる過程 (reply 'Good. Morning) = (cond [(symbol=? 'Good. Morning) 'Hi] [(symbol=? 'How. Are. You 'Good. Morning) 'Fine] [(symbol=? 'Good. Afternoon 'Good. Morning) 'Need. ANap] [(symbol=? 'Good. Evening 'Good. Morning) 'Boy. Am. ITired]) = (cond [true 'Hi] [(symbol=? 'How. Are. You 'Good. Morning) 'Fine] [(symbol=? 'Good. Afternoon 'Good. Morning) 'Need. ANap] [(symbol=? 'Good. Evening 'Good. Morning) 'Boy. Am. ITired]) = 'Hi 79
(reply 'Good. Morning) から 'Hi が得られる過程 (reply 'Good. Morning) = (cond [(symbol=? 'Good. Morning) 'Hi] [(symbol=? 'How. Are. You 'Good. Morning) 'Fine] [(symbol=? 'Good. Afternoon 'Good. Morning) 'Need. ANap] [(symbol=? 'Good. Evening 'Good. Morning) 'Boy. Am. ITired]) = (cond これは, [true 'Hi] (cond [(symbol=? 'How. Are. You 'Good. Morning) 'Fine] [(symbol=? 'Good. Morning s) 'Hi] [(symbol=? 'Need. ANap] [(symbol=? 'Good. Afternoon 'How. Are. You s) 'Good. Morning) 'Fine] [(symbol=? 'Good. Morning) 'Boy. Am. ITired]) = [(symbol=? 'Good. Evening 'Good. Afternoon s) 'Need. ANap] 'Hi [(symbol=? 'Good. Evening s) 'Boy. Am. ITired]) の s を 'Good. Morning で置き換えたもの 80
- Slides: 84