Skip to content

Commit

Permalink
Merge pull request #286 from dan-simon/master
Browse files Browse the repository at this point in the history
Added x and xx example, fixes #278. Also fixes tutorial.
  • Loading branch information
Carl Mäsak committed May 8, 2018
2 parents 657fb55 + 613362b commit a8f6471
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 16 deletions.
1 change: 0 additions & 1 deletion examples/hello-world.007

This file was deleted.

39 changes: 39 additions & 0 deletions examples/x-and-xx.007
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);
9 changes: 0 additions & 9 deletions t/examples/hello-world.t

This file was deleted.

13 changes: 13 additions & 0 deletions t/examples/x-and-xx.t
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;
20 changes: 14 additions & 6 deletions tutorial/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,12 @@ this, the assignment in the `constant` declaration is mandatory.

## Setting

There's a scope outside the program scope, containing a utility
There's a scope outside the program scope, containing a few utility
subroutines. These should be fairly self-explanatory.

say(any)
prompt(any)
type(any)
str(any)
int(any)
min(a, b)
max(a, b)

## Objects

Expand Down Expand Up @@ -233,19 +230,30 @@ The following built-in types have methods associated with them:
.trim()
.split(sep)
.index(substr)
.charat(pos)
.contains(substr)
.substr(pos, chars)
.prefix(pos)
.suffix(pos)
.charat(pos)

### `Array`

.size()
.reverse()
.sort()
.shuffle()
.concat(array)
.join(sep)
.map(fn)
.filter(fn)
.push(newelem)
.pop()
.shift()
.unshift(newelem)

### `Object`

.size()

## Q objects

Expand Down

0 comments on commit a8f6471

Please sign in to comment.