This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 基本的なキーバインド | |
;; | |
;; 基本 | |
;; C-x C-c kill-emacs emacs終了 | |
;; C-g quit 直前のキー操作をキャンセル | |
;; M-x <XXXX><ENTER> lisp-command の直接実行 | |
;; C-h m describe-mode 現在のバッファのキーマップ一覧を表示 | |
;; ファイル操作 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let rec _sum lst ret = match lst with | |
[] -> ret | |
| first :: rest -> _sum rest (ret + first) | |
let sum lst = _sum lst 0 | |
let x = sum [1;2;3] | |
let x = sum [10;2;31] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* 13.5 *) | |
let twice f = let g x = f (f x) in g | |
let f = twice twice | |
(* できあがった関数は渡された関数を4回繰り返したものになる *) | |
(* val f : ('_a -> '_a) -> '_a -> '_a = <fun> *) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* 'a -> 'a *) | |
let func1 a = a | |
(* 'a -> 'b -> 'a *) | |
let func2 a b = a | |
(* 'a -> 'b -> 'b *) | |
let func3 a b = b | |
(* 'a -> ('a -> 'b) -> 'b *) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* データ読み込み *) | |
#use "person_t.ml" | |
(* 目的:person_t のリストから指定された血液型の人数を返す *) | |
(* count_ketsueki : string -> person_t list -> int *) | |
let rec count_ketsueki bld lst = | |
match lst with | |
[] -> 0 | |
| first :: rest -> count_ketsueki bld rest + | |
if (first.blood = bld) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type date_t = { | |
month : int; | |
day : int; | |
} | |
type person_t = { | |
name : string; | |
height : float; | |
weight : float; | |
birthday : date_t; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#use "metro.ml" | |
(* 問題12.1 eki_t 型 *) | |
type eki_t = { | |
namae: string; (* 駅名 *) | |
saitan_kyori: float; (* 最短距離 *) | |
temae_list: string list; (* 通過した駅名のリスト *) | |
} | |
(* 問題12.2 ekimei_t list を受け取って、駅名から eki_t list を作る |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* s から e までの整数のリストを作成する *) | |
let rec makeListSub s e lst = | |
match e - s with | |
0 -> e::lst | |
| _ -> makeListSub s (e-1) (e::lst) | |
let makeList s e = | |
if s < e | |
then makeListSub s e [] | |
else makeListSub e s [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#use "metro.ml" | |
(* 目的:ふたつの駅の漢字の駅名とリストを受け取って2駅間の距離を返す *) | |
(* get_ekikan_kyori : string -> string -> ekikan_t list -> float *) | |
let rec get_ekikan_kyori s1 s2 lst = | |
if s1 = s2 | |
then 0. | |
else match lst with | |
[] -> infinity | |
| first::rest -> if (first.kiten = s1 && first.shuten = s2) || |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#use "metro.ml" | |
(* 目的:ローマ字の駅名と駅名リストから漢字の駅名を返す *) | |
(* romaji_to_kanji : string -> ekimei_t list -> string *) | |
let rec romaji_to_kanji romaji lst = | |
match lst with | |
[] -> "" | |
| first::rest -> if first.romaji = romaji | |
then first.kanji | |
else romaji_to_kanji romaji rest |
NewerOlder