무냐의 개발일지
[OSSU] <UBCx HtC1x_How to Code> / 4a_Self-Reference (Lists, recursion) 본문
OSSU_CS coursework
[OSSU] <UBCx HtC1x_How to Code> / 4a_Self-Reference (Lists, recursion)
무냐코드 2024. 4. 30. 11:12빈 리스트도 리스트다
Base Case를 먼저 test 하는 게 중요하다 !!! 비어있는 리스트인지 아닌지를 먼저 확인!
The base case test should always appear first for self-referential functions, because it's the simplest and all the other tests depened on it being correct.
;;ListOfString is one of:
;; -empty
;; -(cons String ListOfString) ; this is a self-reference
;;interp. a list of strings
;<example>
(define LOS1 empty)
(define LOS2 (cons "McGill" empty))
(define LOS3 (cons "UBC" (cons "McGill" empty)))
| Base Case
| Recursion
요 테이블을 잘 기억하자. 함수를 짤 때 되게 유용하다. base case를 항상 먼저 생각해두자는 점 !
- 좀 쉬운 편이었다! 앞에 compound data가 좀 더 복잡했음
'OSSU_CS coursework' 카테고리의 다른 글
[OSSU] <UBCx HtC1x_How to Code> / 7a_Two One-Of Types (여러가지 경우의 수 생각해서 코드 짜기) (0) | 2024.05.06 |
---|---|
[OSSU] <UBCx HtC1x_How to Code> / 6b_Mutual Reference (0) | 2024.05.05 |
[OSSU] <UBCx HtC1x_How to Code> / 3a_How to Design Worlds (0) | 2024.04.25 |
[OSSU] <UBCx HtC1x_How to Code> / 2_How to Design Data (0) | 2024.04.24 |
[OSSU] <MITx 6.00.1x_Intro CS> Final Exam (0) | 2024.04.23 |