diff --git a/config.json b/config.json index 4175a66..73f3e86 100644 --- a/config.json +++ b/config.json @@ -429,6 +429,14 @@ "prerequisites": [], "difficulty": 3 }, + { + "slug": "house", + "name": "House", + "uuid": "1544058f-dd9a-4ec8-bcb6-e122d74249fc", + "practices": [], + "prerequisites": [], + "difficulty": 5 + }, { "slug": "parallel-letter-frequency", "name": "Parallel Letter Frequency", diff --git a/exercises/practice/house/.docs/instructions.md b/exercises/practice/house/.docs/instructions.md new file mode 100644 index 0000000..88928c5 --- /dev/null +++ b/exercises/practice/house/.docs/instructions.md @@ -0,0 +1,105 @@ +# Instructions + +Recite the nursery rhyme 'This is the House that Jack Built'. + +> [The] process of placing a phrase of clause within another phrase of clause is called embedding. +> It is through the processes of recursion and embedding that we are able to take a finite number of forms (words and phrases) and construct an infinite number of expressions. +> Furthermore, embedding also allows us to construct an infinitely long structure, in theory anyway. + +- [papyr.com][papyr] + +The nursery rhyme reads as follows: + +```text +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. +``` + +[papyr]: https://papyr.com/hypertextbooks/grammar/ph_noun.htm diff --git a/exercises/practice/house/.meta/config.json b/exercises/practice/house/.meta/config.json new file mode 100644 index 0000000..d2c29d9 --- /dev/null +++ b/exercises/practice/house/.meta/config.json @@ -0,0 +1,19 @@ +{ + "authors": [ + "erikschierboom" + ], + "files": { + "solution": [ + "house.8th" + ], + "test": [ + "test.8th" + ], + "example": [ + ".meta/example.8th" + ] + }, + "blurb": "Output the nursery rhyme 'This is the House that Jack Built'.", + "source": "British nursery rhyme", + "source_url": "https://en.wikipedia.org/wiki/This_Is_The_House_That_Jack_Built" +} diff --git a/exercises/practice/house/.meta/example.8th b/exercises/practice/house/.meta/example.8th new file mode 100644 index 0000000..353c313 --- /dev/null +++ b/exercises/practice/house/.meta/example.8th @@ -0,0 +1,23 @@ +[ + "", + "house that Jack built.", + "malt that lay in", + "rat that ate", + "cat that killed", + "dog that worried", + "cow with the crumpled horn that tossed", + "maiden all forlorn that milked", + "man all tattered and torn that kissed", + "priest all shaven and shorn that married", + "rooster that crowed in the morn that woke", + "farmer sowing his corn that kept", + "horse and the hound and the horn that belonged to" +] constant subjects + +: verse \ n -- s + ( subjects swap a:_@ ) 1 rot a:generate a:rev " the " a:join "This is the " swap s:+ +; + +: recite \ n n -- a + ' verse -rot a:generate +; diff --git a/exercises/practice/house/.meta/tests.toml b/exercises/practice/house/.meta/tests.toml new file mode 100644 index 0000000..da24dc3 --- /dev/null +++ b/exercises/practice/house/.meta/tests.toml @@ -0,0 +1,52 @@ +# This is an auto-generated file. +# +# Regenerating this file via `configlet sync` will: +# - Recreate every `description` key/value pair +# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications +# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) +# - Preserve any other key/value pair +# +# As user-added comments (using the # character) will be removed when this file +# is regenerated, comments can be added via a `comment` key. + +[28a540ff-f765-4348-9d57-ae33f25f41f2] +description = "verse one - the house that jack built" + +[ebc825ac-6e2b-4a5e-9afd-95732191c8da] +description = "verse two - the malt that lay" + +[1ed8bb0f-edb8-4bd1-b6d4-b64754fe4a60] +description = "verse three - the rat that ate" + +[64b0954e-8b7d-4d14-aad0-d3f6ce297a30] +description = "verse four - the cat that killed" + +[1e8d56bc-fe31-424d-9084-61e6111d2c82] +description = "verse five - the dog that worried" + +[6312dc6f-ab0a-40c9-8a55-8d4e582beac4] +description = "verse six - the cow with the crumpled horn" + +[68f76d18-6e19-4692-819c-5ff6a7f92feb] +description = "verse seven - the maiden all forlorn" + +[73872564-2004-4071-b51d-2e4326096747] +description = "verse eight - the man all tattered and torn" + +[0d53d743-66cb-4351-a173-82702f3338c9] +description = "verse nine - the priest all shaven and shorn" + +[452f24dc-8fd7-4a82-be1a-3b4839cfeb41] +description = "verse 10 - the rooster that crowed in the morn" + +[97176f20-2dd3-4646-ac72-cffced91ea26] +description = "verse 11 - the farmer sowing his corn" + +[09824c29-6aad-4dcd-ac98-f61374a6a8b7] +description = "verse 12 - the horse and the hound and the horn" + +[d2b980d3-7851-49e1-97ab-1524515ec200] +description = "multiple verses" + +[0311d1d0-e085-4f23-8ae7-92406fb3e803] +description = "full rhyme" diff --git a/exercises/practice/house/house.8th b/exercises/practice/house/house.8th new file mode 100644 index 0000000..344f1ea --- /dev/null +++ b/exercises/practice/house/house.8th @@ -0,0 +1,3 @@ +: recite \ n n -- a + +; diff --git a/exercises/practice/house/libs/exercism/test b/exercises/practice/house/libs/exercism/test new file mode 100644 index 0000000..270681f --- /dev/null +++ b/exercises/practice/house/libs/exercism/test @@ -0,0 +1,174 @@ +needs console/loaded +needs utils/latebind + +\ ----------------------------------------------------------------- + +ns: test + +-1 var, test-count +var tests-passed +var tests-failed +var tests-skipped +true var, run-test + +\ Some utility words + + +: test-passed \ s x x -- \\ test name, expected value, actual value + 2drop + 1 tests-passed n:+! + con:green con:onBlack . space " ... OK" . con:white con:onBlack cr +; + +: test-skipped \ s -- + 1 tests-skipped n:+! + con:cyan con:onBlack . space " ... SKIPPED" . con:white con:onBlack cr +; + +: test-failed \ s x x -- \\ test name, expected value, actual value + 1 tests-failed n:+! + rot + con:red con:onBlack . space " ... FAIL" . con:white con:onBlack cr + " Actual: «" . . "»" . cr + " Expected: «" . . "»" . cr cr +; + +: isword? \ x -- x f + dup >kind ns:w n:= +; + +: run-test? \ -- T + run-test @ if true else "RUN_ALL_TESTS" getenv n:>bool then +; + +\ Num passed + num skipped + num failed should == num tests +: all-tests-run? \ -- T + tests-passed @ tests-skipped @ tests-failed @ n:+ n:+ + test-count @ n:= +; + +\ returns true if x is a date, false otherwise +: date? \ x -- x T + dup >kind ns:d n:= +; + +\ adapted from 8th forum -- https://8th-dev.com/forum/index.php/topic,2745.0.html +: eq? \ x x -- T + \ are the items the same kind? + 2dup >kind swap >kind n:= + !if 2drop false ;then + + \ same kind: try different comparators + number? if n:= ;then + string? if s:= ;then + array? if ' eq? a:= 2nip ;then + map? if ' eq? m:= 2nip ;then + date? if d:= ;then + + \ otherwise fall back to 'lazy evaluation' + G:l: = +; + +: eps_eq? \ n x x -- T + \ are the items the same kind? + 2dup >kind swap >kind n:= + !if 2drop false ;then + number? !if 2drop false ;then + rot n:~= +; + +: check-depth \ ... n -- ... + dup>r + n:1+ depth n:= + !if + con:red con:onBlack + "PANIC: expected stack depth to be " . r> . cr + "Stack is:" . cr + .s cr + 255 die + then + rdrop +; + +\ ----------------------------------------------------------------- + +\ status report at end of run +( all-tests-run? + !if con:red con:onBlack "... FAIL - not all tests completed" . con:white con:onBlack cr then +) onexit + +\ Print a summary of the tests run +( con:white con:onBlack + test-count @ . space "tests planned - " . + tests-passed @ . space "passed - " . + tests-skipped @ . space "skipped - " . + tests-failed @ . space "failed" . cr +) onexit + +\ ----------------------------------------------------------------- +\ The public-facing words +\ ----------------------------------------------------------------- + +: equal? \ s x w -- | s w x -- + run-test? !if 2drop test-skipped ;; then + isword? !if swap then + w:exec + 3 check-depth + 2dup \ so test-failed can show actual and expected + eq? if test-passed else test-failed then +; + +: approx_equal? \ s x w n -- | s w x n -- + run-test? !if 3drop test-skipped ;; then + -rot isword? !if swap then + w:exec + 4 check-depth + 3dup \ so test-failed can show actual and expected + eps_eq? + if rot drop test-passed else rot drop test-failed then +; + +: true? \ s w -- + run-test? !if drop test-skipped ;; then + w:exec + 2 check-depth + true swap dup \ so test-failed can show actual and expected + if test-passed else test-failed then +; + +: false? \ s w -- + run-test? !if drop test-skipped ;; then + w:exec + 2 check-depth + false swap dup \ so test-failed can show actual and expected + !if test-passed else test-failed then +; + +: null? \ s w -- + run-test? !if drop test-skipped ;; then + w:exec + 2 check-depth + null swap dup \ so test-failed can show actual and expected + G:null? nip if test-passed else test-failed then +; + +: SKIP-REST-OF-TESTS false run-test ! ; + +: tests \ n -- + test-count ! +; + +\ Set the exit status: +\ 0 = all OK +\ 1 = not all tests were run (some error occurred) +\ 2 = some tests failed +: end-of-tests \ -- + all-tests-run? + if + tests-failed @ 0 n:= if 0 else 2 then + else + 1 + then + die +; + diff --git a/exercises/practice/house/test.8th b/exercises/practice/house/test.8th new file mode 100644 index 0000000..bcbac3f --- /dev/null +++ b/exercises/practice/house/test.8th @@ -0,0 +1,94 @@ +"house.8th" f:include +needs exercism/test +with: test +14 tests + +"Verse one - the house that jack built" + ( 1 1 recite ) + ["This is the house that Jack built."] + equal? + +SKIP-REST-OF-TESTS + +"Verse two - the malt that lay" + ( 2 2 recite ) + ["This is the malt that lay in the house that Jack built."] + equal? + +"Verse three - the rat that ate" + ( 3 3 recite ) + ["This is the rat that ate the malt that lay in the house that Jack built."] + equal? + +"Verse four - the cat that killed" + ( 4 4 recite ) + ["This is the cat that killed the rat that ate the malt that lay in the house that Jack built."] + equal? + +"Verse five - the dog that worried" + ( 5 5 recite ) + ["This is the dog that worried the cat that killed the rat that ate the malt that lay in the house that Jack built."] + equal? + +"Verse six - the cow with the crumpled horn" + ( 6 6 recite ) + ["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."] + equal? + +"Verse seven - the maiden all forlorn" + ( 7 7 recite ) + ["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."] + equal? + +"Verse eight - the man all tattered and torn" + ( 8 8 recite ) + ["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."] + equal? + +"Verse nine - the priest all shaven and shorn" + ( 9 9 recite ) + ["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."] + equal? + +"Verse 10 - the rooster that crowed in the morn" + ( 10 10 recite ) + ["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."] + equal? + +"Verse 11 - the farmer sowing his corn" + ( 11 11 recite ) + ["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."] + equal? + +"Verse 12 - the horse and the hound and the horn" + ( 12 12 recite ) + ["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."] + equal? + +"Multiple verses" + ( 4 8 recite ) + [ "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." ] + equal? + +"Full rhyme" + ( 1 12 recite ) + [ "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." ] + equal? + +end-of-tests +;with