-
Notifications
You must be signed in to change notification settings - Fork 2
Add support for infix qw sequences.extras #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| diff --git a/extra/shuffle/shuffle.factor b/extra/shuffle/shuffle.factor | ||
| index da69307ce7..d4c0eab80e 100644 | ||
| --- a/extra/shuffle/shuffle.factor | ||
| +++ b/extra/shuffle/shuffle.factor | ||
| @@ -2,8 +2,7 @@ | ||
| ! See https://factorcode.org/license.txt for BSD license. | ||
|
|
||
| USING: accessors assocs combinators combinators.short-circuit | ||
| -definitions effects effects.parser generalizations help | ||
| -help.markup kernel math parser ranges sequences | ||
| +definitions effects effects.parser generalizations kernel math parser ranges sequences | ||
| sequences.generalizations stack-checker.backend | ||
| stack-checker.known-words stack-checker.values words ; | ||
|
|
||
| @@ -26,7 +25,6 @@ SYNTAX: SHUFFLE: | ||
| scan-new-word scan-effect { | ||
| [ [ '[ _ shuffle-effect ] ] keep define-declared ] | ||
| [ "shuffle" set-word-prop ] | ||
| - [ drop { $shuffle } swap set-word-help ] | ||
| } 2cleave ; | ||
|
|
||
| PREDICATE: shuffle-word < word |
37 changes: 37 additions & 0 deletions
37
tests/wishlist-vocabs/exercism-tools/exercism-tools.factor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| USING: accessors command-line continuations debugger io kernel | ||
| lexer namespaces sequences source-files.errors.debugger | ||
| system tools.test vocabs vocabs.loader ; | ||
| IN: exercism-tools | ||
|
|
||
| SYNTAX: STOP-HERE | ||
| lexer get [ text>> length ] keep line<< ; | ||
|
|
||
| SYNTAX: TASK: | ||
| lexer get next-line ; | ||
|
|
||
| ! Label the test that follows with its description. The marker lets the | ||
| ! wrapper strip this line from captured output and attach it to the next | ||
| ! test as a name, rather than leaving it in the previous test's output. | ||
| : description ( str -- ) | ||
| "###DESC### " write print ; | ||
|
|
||
| ! Print one failure block in a stable, parser-friendly form. Bracketed by | ||
| ! markers so a wrapper can split the stream reliably and avoid Factor's | ||
| ! noisy callstack output (which is interleaved with subsequent failures). | ||
| :: print-failure ( failure -- ) | ||
| "###FAIL_BEGIN###" print | ||
| failure error-location print | ||
| failure error>> [ error. ] [ 2drop ] recover | ||
| "###FAIL_END###" print | ||
| flush ; | ||
|
|
||
| : print-failures ( -- ) | ||
| test-failures get [ print-failure ] each ; | ||
|
|
||
| : run-exercism-tests ( -- ) | ||
| command-line get first | ||
| [ require ] [ test ] bi | ||
| test-failures get empty? | ||
| [ 0 exit ] [ print-failures 1 exit ] if ; | ||
|
|
||
| MAIN: run-exercism-tests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| { | ||
| "version": 3, | ||
| "status": "pass", | ||
| "tests": [ | ||
| { | ||
| "name": "qw builds a sequence of strings", | ||
| "status": "pass", | ||
| "test_code": "{ { \"apple\" \"orange\" \"lime\" } } [ fruits ] unit-test" | ||
| }, | ||
| { | ||
| "name": "infix add sums two numbers", | ||
| "status": "pass", | ||
| "test_code": "{ 7 } [ 3 4 add ] unit-test" | ||
| }, | ||
| { | ||
| "name": "take-while keeps the leading run", | ||
| "status": "pass", | ||
| "test_code": "{ { 1 2 } } [ { 1 2 3 4 1 } small-prefix ] unit-test" | ||
| }, | ||
| { | ||
| "name": "interpolate fills in the name", | ||
| "status": "pass", | ||
| "test_code": "{ \"Hello, World!\" } [ \"World\" greeting ] unit-test" | ||
| }, | ||
| { | ||
| "name": "cycle repeats a sequence to length", | ||
| "status": "pass", | ||
| "test_code": "{ { 1 2 3 1 2 } } [ { 1 2 3 } 5 padded-cycle ] unit-test" | ||
| }, | ||
| { | ||
| "name": "circular indexing wraps around", | ||
| "status": "pass", | ||
| "test_code": "{ 20 } [ 4 { 10 20 30 } wrap-nth ] unit-test" | ||
| }, | ||
| { | ||
| "name": "pair-rocket builds an assoc", | ||
| "status": "pass", | ||
| "test_code": "{ H{ { \"ada\" 1 } { \"bob\" 2 } } } [ scores ] unit-test" | ||
| } | ||
| ] | ||
| } |
23 changes: 23 additions & 0 deletions
23
tests/wishlist-vocabs/wishlist-vocabs/wishlist-vocabs-tests.factor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| USING: exercism-tools tools.test wishlist-vocabs ; | ||
| IN: wishlist-vocabs.tests | ||
|
|
||
| "qw builds a sequence of strings" description | ||
| { { "apple" "orange" "lime" } } [ fruits ] unit-test | ||
|
|
||
| "infix add sums two numbers" description | ||
| { 7 } [ 3 4 add ] unit-test | ||
|
|
||
| "take-while keeps the leading run" description | ||
| { { 1 2 } } [ { 1 2 3 4 1 } small-prefix ] unit-test | ||
|
|
||
| "interpolate fills in the name" description | ||
| { "Hello, World!" } [ "World" greeting ] unit-test | ||
|
|
||
| "cycle repeats a sequence to length" description | ||
| { { 1 2 3 1 2 } } [ { 1 2 3 } 5 padded-cycle ] unit-test | ||
|
|
||
| "circular indexing wraps around" description | ||
| { 20 } [ 4 { 10 20 30 } wrap-nth ] unit-test | ||
|
|
||
| "pair-rocket builds an assoc" description | ||
| { H{ { "ada" 1 } { "bob" 2 } } } [ scores ] unit-test |
27 changes: 27 additions & 0 deletions
27
tests/wishlist-vocabs/wishlist-vocabs/wishlist-vocabs.factor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| USING: arrays circular hashtables infix interpolate kernel math | ||
| namespaces pair-rocket qw sequences sequences.extras | ||
| sequences.repeating ; | ||
| IN: wishlist-vocabs | ||
|
|
||
| ! qw{ ... } reads a whitespace-separated literal sequence of strings (qw). | ||
| : fruits ( -- seq ) qw{ apple orange lime } ; | ||
|
|
||
| ! Standard infix arithmetic over locals (infix). | ||
| INFIX:: add ( x y -- z ) x + y ; | ||
|
|
||
| ! take-while keeps the leading run satisfying the predicate (sequences.extras); | ||
| ! it returns a slice, so >array normalizes it for an exact unit-test compare. | ||
| : small-prefix ( seq -- arr ) [ 3 < ] take-while >array ; | ||
|
|
||
| ! ${var} string interpolation, reading from a dynamic variable (interpolate). | ||
| : greeting ( name -- str ) | ||
| [ "name" set "Hello, ${name}!" interpolate>string ] with-scope ; | ||
|
|
||
| ! cycle repeats a sequence up to a given length (sequences.repeating). | ||
| : padded-cycle ( seq n -- arr ) cycle >array ; | ||
|
|
||
| ! <circular> wraps a sequence so indices read modulo its length (circular). | ||
| : wrap-nth ( n seq -- elt ) <circular> nth ; | ||
|
|
||
| ! => pairs each key with the next value, building assoc literals (pair-rocket). | ||
| : scores ( -- assoc ) { "ada" => 1 "bob" => 2 } >hashtable ; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a patch file is a bit messy :(