in reply to Re^4: 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

Definitely not. List assignment takes a list of scalars, and that's exactly what you provided.

Call me naive, but I only see a scalar, not a list of scalars. Still a list of of scalars is a list, not an array, so even @array = ($a, $b) looks to me like a coercion. Likewise @array = foo() coerces the result list to an array. So you have $variable_of_one_type = $variable_of_other_type where the LHS dictates the type of the result.

it's count is assigned, and that's a completely different entity.

The count is an intrinsic property of the @array, and as far as I understand coercion, it is allowed to lose information - just like in other languages coercing a float to int loses the fractional part. I haven't seen a definition of coercion yet that requires the coerced object to retain the essence of what it was, however you define "essence".

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

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

Replies are listed 'Best First'.
Re^6: compiling perl scripts aka why is perl not as fast as C
by ikegami (Patriarch) on Mar 22, 2010 at 17:39 UTC

    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.

      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.