동요 'This is the House that Jack Built'를 암송해요.
어떤 구나 절을 또 다른 구나 절 안에 넣는 과정을 내포라고 해요. 재귀와 내포 과정을 거치면 유한한 수의 형태(단어와 구)를 가지고 무한한 수의 표현을 만들어 낼 수 있어요. 게다가 내포를 이용하면 적어도 이론상으로는 무한히 긴 구조도 만들 수 있어요.
동요는 다음과 같아요.
This is the house that Jack built.
This is the malt
that lay in the house that Jack built.
This is the rat
that ate the malt
that lay in the house that Jack built.
This is the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.
This is the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.
This is the cow with the crumpled horn
that tossed the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.
This is the maiden all forlorn
that milked the cow with the crumpled horn
that tossed the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.
This is the man all tattered and torn
that kissed the maiden all forlorn
that milked the cow with the crumpled horn
that tossed the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.
This is the priest all shaven and shorn
that married the man all tattered and torn
that kissed the maiden all forlorn
that milked the cow with the crumpled horn
that tossed the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.
This is the rooster that crowed in the morn
that woke the priest all shaven and shorn
that married the man all tattered and torn
that kissed the maiden all forlorn
that milked the cow with the crumpled horn
that tossed the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.
This is the farmer sowing his corn
that kept the rooster that crowed in the morn
that woke the priest all shaven and shorn
that married the man all tattered and torn
that kissed the maiden all forlorn
that milked the cow with the crumpled horn
that tossed the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.
This is the horse and the hound and the horn
that belonged to the farmer sowing his corn
that kept the rooster that crowed in the morn
that woke the priest all shaven and shorn
that married the man all tattered and torn
that kissed the maiden all forlorn
that milked the cow with the crumpled horn
that tossed the dog
that worried the cat
that killed the rat
that ate the malt
that lay in the house that Jack built.
이 연습 문제는 코드 리팩터링에 관한 것이기 때문에, 이미 테스트를 통과하는 풀이를 함께 제공해요.
여기서의 목표는 스스로 만족할 때까지 이 풀이를 다시 작성해 보고, 그 과정에서 무언가를 배우는 거예요.
어디서부터 시작해야 할지 모르겠다면, 이런 방법을 시도해 봐요:
서두르지 않아도 괜찮아요.
한 번에 한 가지만 바꾸고, 풀이가 여전히 테스트를 통과하는지 확인해 봐요.
즐겁게 해봐요!