-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #286 from dan-simon/master
Added x and xx example, fixes #278. Also fixes tutorial.
- Loading branch information
Showing
5 changed files
with
66 additions
and
16 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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,39 @@ | ||
macro infix:<xx>(left, right) is equal(infix:<*>) { | ||
# Flattens one layer. | ||
sub flatten (inputList) { | ||
my result = []; | ||
for inputList -> i { | ||
if (type(i) == type([])) { | ||
for i -> j { | ||
result.push(j); | ||
} | ||
} else { | ||
result.push(i); | ||
} | ||
} | ||
return result; | ||
} | ||
return quasi { | ||
flatten((^{{{right}}}).map(sub getValue(ignore) { | ||
return {{{left}}}; | ||
})) | ||
} | ||
} | ||
|
||
sub infix:<x>(left, right) is equal(infix:<*>) { | ||
return (left xx right).join(""); | ||
} | ||
|
||
# Test string x number. | ||
say("testing" x 2); | ||
|
||
# Test number xx number. | ||
my i = 0; | ||
say((i = i + 1) xx 3); | ||
|
||
# Test list xx number. | ||
say([1, 2, 3] xx 2); | ||
|
||
# Test (list or number) xx number. | ||
my j = 0; | ||
say((j = [1, [1, 2, 3]][j && 1]) xx 2); |
This file was deleted.
Oops, something went wrong.
This file contains 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,13 @@ | ||
use Test; | ||
use _007::Test; | ||
|
||
my @lines = run-and-collect-output("examples/x-and-xx.007"); | ||
|
||
is +@lines, 4, "correct number of lines"; | ||
|
||
is @lines[0], "testingtesting", "first line"; | ||
is @lines[1], "[1, 2, 3]", "second line"; | ||
is @lines[2], "[1, 2, 3, 1, 2, 3]", "third line"; | ||
is @lines[3], "[1, 1, 2, 3]", "fourth line"; | ||
|
||
done-testing; |
This file contains 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