-
Notifications
You must be signed in to change notification settings - Fork 14
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
Added x and xx example, fixes #278. Also fixes tutorial. #286
Changes from all commits
c6014ea
6becb55
03abe63
be2d3db
70e4002
a427c6f
613362b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
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); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shorter and no less clear than the |
||
} else { | ||
result.push(i); | ||
} | ||
} | ||
return result; | ||
} | ||
return quasi { | ||
flatten((^{{{right}}}).map(sub getValue(ignore) { | ||
return {{{left}}}; | ||
})) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is beautiful. ❤️ |
||
} | ||
} | ||
|
||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No worries for now, but given the way #279 is heading, this expression might become illegal soon. Just a heads-up. 😄 It's an interesting way to check for something — if we outlaw assignment expressions, we'll have to make sure to have an alternative in place for this one. |
This file was deleted.
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; |
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.
This works, but more idiomatic to use type matching:
if i ~~ Array
.