Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sub appends Nil to the end in Raku

Tags:

raku

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?

like image 655
Lars Malmsteen Avatar asked Jan 09 '21 18:01

Lars Malmsteen


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);
like image 152
Holli Avatar answered Jan 12 '23 06:01

Holli