Interpolation of arrays

2 views
Skip to first unread message

phil...@sunflower.com

unread,
Aug 5, 2005, 12:46:19 PM8/5/05
to perl6-c...@perl.org
While trying to use say for debugging, I ran across an oddity. While I can:
say "{@some_array}";
and
say @some_array;
this doesn't work:
say "@some_array";

Even stranger:
class SomeClass {
has $.scalar_attr;
has @.array_attr;
method trial () {
say "$.scalar_attr @.array_attr";
}
}
Calling trial yields the correct value of the scalar, but the literal '@.array_attr' instead of its value. Oddly, substituting $.array_attr yields the value with no complaint that there is no such scalar.

Am I missing something, or should I submit a test?

If the later, what folder should I put it in?

Phil

Ingo Blechschmidt

unread,
Aug 5, 2005, 1:01:40 PM8/5/05
to perl6-c...@perl.org
Hi,

phil...@sunflower.com wrote:
> While trying to use say for debugging, I ran across an oddity. While
> I can:
> say "{@some_array}";
> and
> say @some_array;
> this doesn't work:
> say "@some_array";

Pugs is correct here, you need to use [] or {} to interpolate
aggregates:

say "$scalar @array[] %hash{}";

> Even stranger:
> class SomeClass {
> has $.scalar_attr;
> has @.array_attr;
> method trial () {
> say "$.scalar_attr @.array_attr";
> }
> }
> Calling trial yields the correct value of the scalar, but the literal
> '@.array_attr' instead of its value. Oddly, substituting $.array_attr
> yields the value with no complaint that there is no such scalar.

Ah, that's probably because under the current runcore, all $.vars are
merely keys for a hash, and the sigil seems to get stripped away.

(Under the new PIL runcore, Stevan's metamodel will be/is integrated,
i.e. we'll have "real" OO, and accessing
$.attributes_which_do_not_exist will fail at compile-time.)

> Am I missing something, or should I submit a test?

Yes, please do so! :)

> If the later, what folder should I put it in?

t/oo/attributes/, probably.


--Ingo

--
Linux, the choice of a GNU | self-reference, n. - See self-reference
generation on a dual AMD |
Athlon! |

Patrick R. Michaud

unread,
Aug 5, 2005, 12:51:56 PM8/5/05
to phil...@sunflower.com, perl6-c...@perl.org
On Fri, Aug 05, 2005 at 11:46:19AM -0500, phil...@sunflower.com wrote:
> While trying to use say for debugging, I ran across an oddity. While I can:
> say "{@some_array}";
> and
> say @some_array;
> this doesn't work:
> say "@some_array";

If you're expecting to see the contents of @some_array, you probably
mean:

say "@some_array[]";

See S02.

Pm

Reply all
Reply to author
Forward
0 new messages