http://www.perlmonks.org?node_id=830116


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

Is that no coercion?

Replies are listed 'Best First'.
Re^5: compiling perl scripts aka why is perl not as fast as C
by moritz (Cardinal) on Mar 22, 2010 at 17:26 UTC
    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.

      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.
Re^5: compiling perl scripts aka why is perl not as fast as C
by Hue-Bond (Priest) on Mar 22, 2010 at 17:50 UTC
    @array acts like a function. It takes an arg and returns a value based on the input and context.

    Excuse me but, what would be the argument?

    --
     David Serrano
     (Please treat my english text just like Perl code, i.e. feel free to notify me of any syntax, grammar, style and/or spelling error. Thank you!).

      The array / array name / pad slot
      sub array { my ($self) = @_; wantarray ? $self->length : $self->contents }