2020.04.10 초안작성
EOPL 책을 학습하면서 접하게 되는 Scheme 언어에 대한 기초적인 지식을 정리하고자 본 글을 정리하였습니다. 본 글은 DrRacket과 EOPL을 기준으로 작성되었습니다.
2020.04.10 초안작성
EOPL 책을 학습하면서 접하게 되는 Scheme 언어에 대한 기초적인 지식을 정리하고자 본 글을 정리하였습니다. 본 글은 DrRacket과 EOPL을 기준으로 작성되었습니다.
2020.04.10 초안작성
참고
프로그래밍에서 Datatype은 크게 두가지로 구분할 수 있습니다.
첫 째로 언어에서 기본으로 제공을 해 주는 Datatype으로 보통 Primitive Data Type 이라고 부르는 것입니다.
Built-in Data Type, Intrinsic DataType 이라는 비슷한 느낌의 다른 단어들도 있습니다. 보통 Primitive DataType은 LISP 같은 컴파일러 언어에서 제공해주는 컴파일러 정의 데이터타입을 가리킬 때 자주 사용되는 용어입니다. 보통 Built-in DataType은 틀린 말은 아닌데, 보통 Built-in 이라는 접두사는 Built-in Function 같이 쓰입니다. (그것은 아마도 Primitive Function이라는 용어가 이미 수학에 있기 때문인 것 처럼 보입니다.) 더 정확히 말해서, Primitive Datatype은 아니지만 Built-in Datatype일 수는 있을겁니다. 보통 Intrinsic Datatype 이라는 단어는 무척이나 low한 레벨에서 쓰이는 경향이 있습니다. Intrinsic 이라는 단어가 가지는 억양이 무척이나 강해서, 거의 완전 CPU 레벨단으로 까지 내려가는(본질적인) 그런 것처럼 느껴집니다.
두번 째로 프로그래머가 해당 언어가 제`공해주는 Syntax를 통하여 직접 Custom 해서 사용하는 Data Type입니다. C언어에서는 Structure, 다른 보통의 언어에서 말하는 Class나 Object가 이것에 해당합니다.
현재기준, DrRacket에는 19개의 Built-in Datatype이 있습니다. 이 중에서 EPOL을 학습하며 앞으로 자주 사용하게될 데이터타입들 부터 살펴보겠습니다.
(boolean? #f)
#t
(boolean? #t)
#t
(boolean? 'true)
#f(not #f)
#t
(not #t)
#f
(not 'this-is-string)
#f
(equal? #t #t)
#t
(equal? #t #f)
#f
(equal? 2 2.0)
#f
(equal? 'hihi 'hihi)
#t
(> 1 2)
#f
(> 2 1)
#t
(> 2 2)
#f
(>= 2 2)
#t
(equal? 2 2)
#t
complex number
real number
rational number
integer
some special numbers(infinity, single-precision variant etc...)
(number? 1)
#t
(number? 2+3i)
#t
(number? +nan.0)
#t
(real? 1)
#t
(real? 2+3i)
#f
(real? 'hello)
f
(rational? 1)
#t
(rational? +inf.0)
#f
(rational? 'hello
#f
(integar? 1)
#t
(integer? 2.3)
#f
(integer? 2.0)
#t
(inteher? 'hello)
(string? 'Apple)
#f
(string? "Apple")
#t
(string-length "Apple")
5
(string-ref "Apple" 0)
#\A
(substring "Apple" 1 3)
"pp"
(string-append "Apple" "Banana")
"AppleBanana"
(string=? "Apple" "Apple")
#t
(string=? "Apple" "apple")
#f
(string-ci=? "Apple" "apple")
#t
(string-upcase "abc!")
"ABC!"
(string-foldcase "aBC!")
"abc!"
(pair? 1)
#f
(pair? (cons 1 2))
#t
(pair? (list 1 2))
#t
(pair? '(1 2))
#t
(pair? '(1))
#t
(pair? '(1 2 3))
#t
(pair? '())
#f
(null? '())
#t
(null? (cdr (list 1)))
#t
2020.04.10 초안작성
참고
Pairs and Lists Reference SICP 2.2
LISP 에서 표현능력의 핵심은 LISP(LISt Processing)이라는 이름에서도 알아볼 수 있듯이 list에 있습니다. 그 중에서도 특히나 pair 객체에 중점이 있는 것 처럼 보입니다.
(cons 1 2)
(1 . 2)
(cons (cons 1 2) 3)
((1 . 2) . 1)
(car (cons (cons 1 2) 3))
(1 . 2)
(cdr (cons (cons 1 2) 3))
3
(map (lambda (number)(+ 1 number)) (list 1 2 3 4))
(2 3 4 5)
(for-each (lambda (arg) (write arg)) (list 1 2 3 4))
1234
(filter positive? '(1 -2 3 4 -5))
(1 3 4)
(remove 2 (list 1 2 3 2 4))
(1 3 2 4)