sub appends Nil to the end in Raku

Viewed 81
my sub e($r) { printf("%d, ", $_) for 1..$r}
say e(5);

returns 1, 2, 3, 4, 5, Nil that is, the sub and/or say consistently adds a Nil to the end.

I first tried it using rakudo version 2020.02. I've tried now using the latest version 2020.12.1 and that Nil is still there. How to get rid of it?

1 Answers

Nil is the return value of the sub e.

You either want

my sub e($r) { printf("%d, ", $_) for 1..$r}
e(5);

or

my sub e($r) { map { sprintf("%d, ", $_) }, 1..$r }
.say for e(5);
Related