第2章練習問題
This file contains 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
(* --- 問題2.1 --- *) | |
# 7 - 3 * 4 ;; | |
- : int = -5 | |
(* 乗除算の順序は交換可能だが整数型なので *) | |
(* 7 / 2 は 3と評価ので,以下の2式の結果は異なる *) | |
# 7 / 2 * 2 ;; | |
- : int = 6 | |
# 7 * 2 / 2 ;; | |
- : int = 7 | |
(* --- 問題2.2 --- *) | |
# 2.0 *. 3.14 *. 10. ;; | |
- : float = 62.8000000000000043 | |
# 1.73 ** 2.0 ;; | |
- : float = 2.9929 | |
# 7.0 /. 2.0 ;; | |
- : float = 3.5 | |
(* --- 問題2.3 --- *) | |
# "東京" ^ "特許" ^ "許可局" ^ "局長" ;; | |
- : string = "東京特許許可局局長" | |
(* 実際には存在しません… *) | |
# "関数" ^ "型" ^ "言語" ;; | |
- : string = "関数型言語" | |
(* --- 問題2.4 --- *) | |
# 2 > 3 ;; | |
- : bool = false | |
(* 以下の2式は等価 *) | |
(* "10は3.1415の2乗より小さい"を否定している *) | |
# not (3.1415 ** 2.0 > 10.0) ;; | |
- : bool = true | |
(* 否定により">"を反転すると"<="となる *) | |
# 3.1415 ** 2.0 <= 10.0 ;; | |
- : bool = true | |
# (8 mod 3) = 2 ;; | |
- : bool = true | |
# 8 mod 3 = 2 ;; | |
- : bool = true | |
# (3 + 4 + 5) = (4 * 3) ;; | |
- : bool = true | |
# 3 + 4 + 5 = 4 * 3 ;; | |
- : bool = true | |
(* 算術演算子は論理演算子よりも優先順位が高い *) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment