プログラミング学習日記

プログラミング学習時のメモ帳。

DrRacketでSchemeを触ってみる

間違っている場所あったら優しく教えてね

画面の上半分を definitions areaという
- 変更するとSAVEボタンが現れる

プログラムでは数式を使うよ! 今回は( )で囲んでね
RUNボタンを押したら下のinteraction areaに実行結果が表示されるよ
このエリアに書かれている>はあなたに対して新たな数式の入力を待っているよ.
ここで書いたらdefinition area と同じように評価してくれます.(return や enter)で実行される

数字や数式だけでなく 文字テキストや真理値, image画像なども使えるよ

string

"で囲ったものはstringとなる

> (string-append "hello " "world")
"hello world"
(animate hoge)

数学

BSLは数字についていいうとnaturalnumber integer rea;numbr complexnumber を扱います.
BSLではexact number と`inexact numberを区別します. 例えばexact numberで計算する時は可能な限り正確性を保証します. ルート2などは#i`の接頭辞がつきおおよその数であることは警告してくれます.
面倒なので関数を使用する時はdefiinitions areaで先に定義しておこう

文字列

string型のこと.
文字列生成の関数はstring-appendしかありません.

substring 
string-append
string-length
number->string
string=?
数学的画像について

図形などの描画ができます

circle
ellipse
line
rectangle
text
triangle
star
empty-scene (四角形)

image-width や image-height で取得できます.

Booolean

true #false の2種類があります.

if文

if elseは存在しない. trueかfalseの2たくのif文

(if ( 条件式 ) (trueの値) (falseの値) )

関数の定義

(define (f x ) (* x x))

練習

階乗の計算

(define (func x) (if (= x 1) 1 (* x (sub1 x))))

Ex

//ex11
(define (distance x y ) (sqrt (+ (* x x) (* y y))))
//ex12
(define (cvolume x) (* x x x))
/ex12-2
(define (csurface x) (* x x 6))
//ex13
(define (string-first x) (if (not (string? x)) "this value is not string" (substring x 1)))
//ex14
(define (string-last x) (if (not (string? x)) "this value is not string" (substring x (sub1 (string-length x)))))
//ex15
(define sunny #true)
(define friday #false)
(define (==> weather dayOfWeek) (or (not weather) dayOfWeek))
//ex16
(define (image-area x) (* (image-width x) (image-height x)))
//ex17
(define (image-classify x) (cond
                            [ (< (image-width x) (image-height x)) "tall"]
                            [ (> (image-width x) (image-height x)) "wide"]
                            [else "square"]))
//ex18
(define (string-join x y) (string-append x "_" y))
//ex19
(define (string-insert str i) (string-append (substring str 0 i) "_" (substring str i)))
//ex20
(define (string-delete x i) (string-append (substring x 0 (sub1 i)) (substring x i)))

2.2

3つのプロセスで実行されます.
1. 引数の関数の評価を行います. 2.

英単語

  • mixed decimal 帯少数(整数 + 少数)
  • preserve 保存する
  • novice 初心者
  • fraction 端数
  • irrational number 無理数
  • digits 桁
  • Cartsian デカルト
  • coordinate 座標
  • Cartesian coordinate system デカルト座標系, 直交座標系
  • cumbersome 面倒 -prejudice 偏見
  • succumb 屈する
  • horrible 恐ろしい
  • ellipse 楕円
  • equilateral 等辺
  • tandem 縦に並んだ
  • algebra 代数

ブログを見ていただきありがとうございました