in reply to Re^5: compiling perl scripts aka why is perl not as fast as C
in thread compiling perl scripts aka why is perl not as fast as C

Call me naive, but I only see a scalar, not a list of scalars.

A list of one scalar is still a list of scalars. You know that parens aren't the what make lists.

Still a list of of scalars is a list, not an array

Ok, so you say the coercion that occurs is from list to array. If that's true, then

my @a = @b;

also does coercion (array to list, then list to array), and the topic becomes irrelevant and silly. It may be true, but the concept is completely useless and not worth discussing.

So you haven't convinced me in either case that not coercion is happening.

I concede it's at best a grey area, and not one I care much about.

Update: Added last bit.

Replies are listed 'Best First'.
Re^7: compiling perl scripts aka why is perl not as fast as C
by moritz (Cardinal) on Mar 22, 2010 at 17:57 UTC
    Ok, so you say the coercion that occurs is from list to array. If that's true, then
    my @a = @b;
    also does coercion (array to list, then list to array), and the topic becomes irrelevant and silly. It may be true, but the concept is completely useless and not worth discussing

    I think the main issue is that we're talking about different levels: When I look at Perl code, I don't see that my @a = @b does a coercion to list and back again - so to me it doesn't happen. You seem to know that either by knowing the core or by memorizing some rules that are not obvious from looking at Perl code, or the documentation in perlsyn et al.

    So to me the isomorphism of a list of a single scalar and a list containing a single scalar also does not exist - When I see $foo, I think "this is a scalar" and not "this is a scalar, also constituting a list of a single scalar". It's the assignment that turns the RHS of my @a = $b into a list, and that's what I call coercion.

    Perl 6 - links to (nearly) everything that is Perl 6.

      You seem to know that either by knowing the core

      Quite the contrary. I'm viewing at a high level.

      Let's look at foreach loops for a second. A foreach loop iterates over a list. It's how it's documented. It's how it works conceptually. The list can from a list literal, a range, an array, a function, etc. Internally, foreach treats ranges and arrays specially, but conceptually, it works on a list.

      I don't see the list assignment any differently. As far as I'm concerned, the list assignment is an operator that takes a list and assigns it to a list or an array. That view is independent of the actual implementation. If I were to peak into the core, it wouldn't surprise me that @a=@b is optimised to avoid creating a list. But like you said, the internal specifics aren't being discussed.

      That's how I see it.

      Update: Added foreach example.