diff --git a/examples/hello-world.007 b/examples/hello-world.007 deleted file mode 100644 index dd3046db..00000000 --- a/examples/hello-world.007 +++ /dev/null @@ -1 +0,0 @@ -say("Hello, world!"); diff --git a/examples/x-and-xx.007 b/examples/x-and-xx.007 new file mode 100644 index 00000000..d67c2f65 --- /dev/null +++ b/examples/x-and-xx.007 @@ -0,0 +1,39 @@ +macro infix:(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:(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); diff --git a/t/examples/hello-world.t b/t/examples/hello-world.t deleted file mode 100644 index 135d3c8a..00000000 --- a/t/examples/hello-world.t +++ /dev/null @@ -1,9 +0,0 @@ -use Test; -use _007::Test; - -my @lines = run-and-collect-output("examples/hello-world.007"); - -is +@lines, 1, "one line of output"; -is @lines[0], "Hello, world!", "correct output"; - -done-testing; diff --git a/t/examples/x-and-xx.t b/t/examples/x-and-xx.t new file mode 100644 index 00000000..2cff2125 --- /dev/null +++ b/t/examples/x-and-xx.t @@ -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; diff --git a/tutorial/README.md b/tutorial/README.md index a34d626b..c8358e7c 100644 --- a/tutorial/README.md +++ b/tutorial/README.md @@ -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 @@ -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