무냐의 개발일지

[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)))

 

 

YES !

 

 

 

|  Base Case

 

 

 

| Recursion

 

 

요 테이블을 잘 기억하자. 함수를 짤 때 되게 유용하다. base case를 항상 먼저 생각해두자는 점 ! 

 

-  좀 쉬운 편이었다! 앞에 compound data가 좀 더 복잡했음