무냐의 개발일지
[OSSU] <UBCx HtC1x_How to Code> / 1a_ BSL Programming 본문
복잡한 문제를 더 깔끔하게 만드는 것 : systematic program design
진짜 중요한 강의가 될듯!!
BSL(Beginning Student Language) 을 통해 다른 언어들에 적용할 수 있다
Program design is something you learn by doing !!!
| 기본적인 사용법 (int, string, 도형만들기(overlay, beside, above))
; expressions, integers
;(+ 3 4)
;(+ 3 ( * 2 3))
;(/ 12 (* 2 3))
(sqr 3)
(sqrt 16)
(+ 3 4)
(sqrt 2)
(/ (* 2 3) 2)
(/ 2 (* 2 3))
(+ 2 (* 3 4) (- (+ 1 2) 3))
;strings
"apple"
"Ada"
(string-append "Ada" " " "Lovelace")
(string-length "Apple")
(substring "Caribou" 2 4)
(substring "0123456" 1 5)
(string-append "oh" "Ana")
;image
(require 2htdp/image)
(circle 10 "solid" "red")
(rectangle 30 60 "outline" "blue")
(text "hello" 24 "orange")
(above (circle 10 "solid" "red")
(circle 20 "solid" "yellow")
(circle 30 "solid" "green"))
(overlay (circle 10 "solid" "red")
(circle 20 "solid" "yellow")
(circle 30 "solid" "green"))
(overlay (text "STOP" 48 "white")
(regular-polygon 60 8 "solid" "red"))
(beside (square 20 "outline" "blue")
(above (circle 15 "solid" "red")
(triangle 20 "solid" "green")))
(above (text "snowman" 30 "black")
(overlay (beside (circle 5 "solid" "black")
(circle 5 "solid" "black"))
(circle 50 "outline" "blue"))
(circle 70 "outline" "blue"))
| 변수 설정 (define 이름 적용할value)
(define CAT [image])
(define RCAT (rotate -30 CAT))
(define LCAT (rotate 30 CAT))
RCAT
이렇게 옆으로 돌아가있어!!! 귀여워!!!!
| Function
(require 2htdp/image)
(define (bulb c)
(circle 40 "solid" c))
(bulb "purple")
(above (bulb "red")
(bulb "purple")
(bulb "green"))
(bulb (string-append "re" "d")) ;red
(define (foo a b)
(+ (* 3 a)
b
(* b a)))
(foo (+ 1 1) 4)
| Boolean
(define WIDTH 200)
(define HEIGHT 100)
(> WIDTH HEIGHT)
(>= WIDTH HEIGHT)
(= 1 2)
(< 3 9)
(require 2htdp/image)
(define I1 (rectangle 10 20 "solid" "red"))
(define I2 (rectangle 20 10 "solid" "blue")) ; width x height
(< (image-width I1) (image-width I2))
(> (image-height I1) (image-height I2))
(if (< (image-width I1) (image-height I1)) "tail" "wide")
"--------------------"
(and (< (image-width I1) (image-width I2))
(> (image-height I1) (image-height I2)))
(not