Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does comb behave differently inside the loop?

Tags:

raku

Note: I'm doing this all from the REPL using This is Rakudo Star version 2019.03.1 built on MoarVM version 2019.03 implementing Perl 6.d.

From euler project #22 there is a names.txt file similar to "JERE","HAI","ELDEN","DORSEY","DARELL","BRODERICK","ALONSO", ...

When I read that in, split and sort it I get the list of names as I'd expect.

for '../names.txt'.IO.slurp.split(',').sort -> $name {
    say $name;
}

That prints out

...
"ZONIA"
"ZORA"
"ZORAIDA"
"ZULA"
"ZULEMA"
"ZULMA"

Now if I add comb()

for '../names.txt'.IO.slurp.split(',').sort -> $name {
    say $name.comb;
}

I'm getting

...
(" Z O N I A ")
(" Z O R A ")
(" Z O R A I D A ")
(" Z U L A ")
(" Z U L E M A ")
(" Z U L M A ")

However, if I just run from the repl;

> "ZULMA".comb

I get

(Z U L M A) # Note the lack of quotes

Why is comb behaving differently in these two scenarios?

like image 212
jmcneirney Avatar asked Nov 21 '19 14:11

jmcneirney


1 Answers

It's not behaving differently. In one case the quotes are a syntax element - part of the code - and in the other case data read verbatim from the file:

"ZULMA".comb
'"ZULMA"'.comb

The data is different. not the behaviour.

like image 82
Holli Avatar answered Jan 14 '23 22:01

Holli