this is annoying

Discussion in 'Perl Misc' started by Mr P, Oct 3, 2006.

  1. Mr P

    Mr P Guest

    shift split /\s+/, @$tx;

    Type of arg 1 to shift must be array (not split) at
    /production/fe/users/feot/acs/ACS_Spex.pm line 5, near "$tx )"

    shift ( split /\s+/, @$tx );
    (same error)

    It doesn't make sense that I can do:

    @array = arrayOp args

    but I can't do

    @array = arrayOp1 (arrayOp2 args)


    **********************************************

    Larry you almost always make things work as expected, but for
    perlfunction "chains" like

    op1 op2 op3 ... opn arg

    everything is almost always busted. This is "the stuff" of clean,
    concise syntax (chains) and they don't often work in Perl.

    scalarOp (stuff)
    should always try its best to turn "stuff" into a scalar
    (precedence-rules followed of course)

    Likewise,
    arrayOp (stuff)

    should always try its best to turn "stuff" into an array, coercing
    lists if necessary

    and of course likewise for hashes

    This is particularly true when using parens around stuff- can't make it
    much clearer than that to the parser!

    Larry I've heard you say personally that your intended design on Perl
    was that "things would always always work as you'd expect". That's true
    for almost every simple case like

    operator args

    and not true for almost every compound case.

    Get your knives out Uri et al, but this is annoying, depsite your
    defense that Perl design is "always right", and comp scientsts opposing
    views are "always wrong". (I've read myriad responses to that effect).


    I'll do it in individual lines, whatever..

    Rant --
     
    Mr P, Oct 3, 2006
    #1
    1. Advertising

  2. Mr P

    Paul Lalli Guest

    Mr P wrote:
    > shift split /\s+/, @$tx;
    >
    > Type of arg 1 to shift must be array (not split) at
    > /production/fe/users/feot/acs/ACS_Spex.pm line 5, near "$tx )"
    >
    > shift ( split /\s+/, @$tx );
    > (same error)


    Ignoring for a moment your case that shift should be able to work on
    lists, I don't have any idea what you think that should be doing.
    split takes an expression and returns a list. You're giving it an
    array. What is it supposed to be splitting?

    > It doesn't make sense that I can do:
    >
    > @array = arrayOp args
    >
    > but I can't do
    >
    > @array = arrayOp1 (arrayOp2 args)


    It makes perfect sense, actually. You seem to either not understand or
    not like that shift does two separate things. It both returns the
    first argument of the array *AND MODIFIES THAT ARRAY*. It is not
    possible to modify a list. That's one of the key differences between a
    list and an array. Please see: perldoc -q difference

    Now, if you want to make the case that shift() should be able to detect
    whether its argument is an array or a list, and not do this second
    feature of modification if it's just a list, that's fine. You'll
    probably even get a lot of agreement there. But to say that it
    "doesn't make sense" for shift() to work the way it does is just
    pointless.

    Have you considered trying to write a wrapper subroutine that will do
    what you want? If passed an array (or possibly necessarily an array
    reference?), remove and return the first element, but if passed a list,
    just return the first element.

    > Get your knives out Uri et al, but this is annoying, depsite your
    > defense that Perl design is "always right", and comp scientsts opposing
    > views are "always wrong". (I've read myriad responses to that effect).


    Now what the hell is the point of this? Are you looking for solutions,
    to improve Perl and the experience of Perl programmers? Or are you
    just looking to whine bitch moan complain and insult?

    Paul Lalli
     
    Paul Lalli, Oct 3, 2006
    #2
    1. Advertising

  3. Mr P

    -berlin.de Guest

    Mr P <> wrote in comp.lang.perl.misc:
    > shift split /\s+/, @$tx;
    >
    > Type of arg 1 to shift must be array (not split) at
    > /production/fe/users/feot/acs/ACS_Spex.pm line 5, near "$tx )"
    >
    > shift ( split /\s+/, @$tx );
    > (same error)


    As Paul Lalli has noted in his excellent reply, the second argument
    of split() should be a string, not an array. I'll assume $str instead
    of @$tx.

    Even then, what do you expect your code to do? You do nothing with
    the return value of shift(), so that doesn't appear to be the point.
    But even if Perl turned the list returned by split into an array
    to suit you, the array would not be accessible after the statement
    is done, so that doesn't seem to be the point either. So what is
    it?

    >
    > It doesn't make sense that I can do:
    >
    > @array = arrayOp args
    >
    > but I can't do
    >
    > @array = arrayOp1 (arrayOp2 args)


    How does this correspond to your code? Specifically, what are
    arrayOp1 and arrayOp2? Is arrayOp1 shift() and arrayOp2 split()?
    In that case, what is an array operator? Something like shift()
    that operates on an array (but returns a single scalar)? Or something
    like split() that works on one to three scalar arguments and returns
    something array-like (a list)? Explain your terminology.

    [...]

    > should always try its best to turn "stuff" into an array, coercing
    > lists if necessary


    Well, Perl as it is doesn't do that for you. It does very little of
    its DWIM with behind-the-scene processing. (I've heard mumblings
    like "...if we keep the array/list distinction" from the Perl 6 corner,
    so there my be hope.)

    You can do it yourself however:

    shift @{ [ split ' ', $str] };

    What would be the advantage if Perl did that automatically? The
    anonymous array (which is indeed decapitated by shift) isn't accessible.
    The return value is easier and more efficiently captured by

    my ( $x) = split ' ', $str;

    Anno
     
    -berlin.de, Oct 3, 2006
    #3
  4. Mr P

    Paul Lalli Guest

    Michele Dondi wrote:
    > On 3 Oct 2006 17:01:27 GMT, -berlin.de wrote:
    >
    > >As Paul Lalli has noted in his excellent reply, the second argument
    > >of split() should be a string, not an array. I'll assume $str instead
    > >of @$tx.

    >
    > And I had thought that if e.g. $tx=['foo',2], then it would be awkward
    > but work. However a quick experiment seems to imply it doesn't...


    Nope. split() is prototyped to take 1, 2, or 3 scalars. Therefore, an
    array passed as the EXPR is treated in scalar context:

    perl -le'
    my @letters = ("a".."z");
    my @foo = split //, @letters;
    print "@foo";
    '
    2 6

    Paul Lalli
     
    Paul Lalli, Oct 3, 2006
    #4
  5. Mr P

    -berlin.de Guest

    Michele Dondi <> wrote in comp.lang.perl.misc:
    > On 3 Oct 2006 06:24:55 -0700, "Mr P" <> wrote:


    > But you're aware that
    >
    > : split /PATTERN/,EXPR,LIMIT
    > : split /PATTERN/,EXPR
    > : split /PATTERN/
    > : split Splits the string EXPR into a list of strings and returns that
    >
    > Aren't you? So unless @$tx contains an "EXPR,LIMIT" couple you're
    > doing something strange.


    That's a valiant attempt to justify MisterPerl's broken code, but even
    that won't work. The second argument of split() is evaluated in scalar
    context. An array in that position is equivalent to the number of its
    elements. It will split an unsigned integer, which will rarely make
    sense.

    Anno
     
    -berlin.de, Oct 3, 2006
    #5
  6. Mr P <> wrote:

    > shift split /\s+/, @$tx;
    >
    > Type of arg 1 to shift must be array (not split) at
    > /production/fe/users/feot/acs/ACS_Spex.pm line 5, near "$tx )"



    Are you going to continue to post this annually until you get an
    answer that you like?

    Message-ID: <>


    > Larry you almost always make things work as expected,


    > Larry I've heard you say personally that your intended design on Perl
    > was that "things would always always work as you'd expect".



    Larry has not participated here for many years. He is not seeing
    your sage advice.

    Even if you repeat it here every 12 months, he still won't see it.

    If you post your patch to p5p he might see it...


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Oct 3, 2006
    #6
  7. Paul Lalli <> wrote:
    > Mr P wrote:


    >> Get your knives out Uri et al, but this is annoying, depsite your
    >> defense that Perl design is "always right", and comp scientsts opposing
    >> views are "always wrong". (I've read myriad responses to that effect).

    >
    > Now what the hell is the point of this?



    MrP> There will probably be a plethora of criticisms about this response.
    MrP> Don't be put off by them, there are a few folks here who really want to
    MrP> assist others. Just figure out who they are and screen the rest. There
    MrP> are some great people here but you need to pay attention to who are
    MrP> here just to criticize.

    in Message-ID: <>

    Which is exceedingly rich, considering the source...


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Oct 3, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eric J. Roode
    Replies:
    0
    Views:
    973
    Eric J. Roode
    Jul 19, 2003
  2. Wolfgang Kaml
    Replies:
    10
    Views:
    743
    Wolfgang Kaml
    Feb 3, 2004
  3. Paul M

    Annoying drop down list...

    Paul M, Jan 23, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    347
    Michael
    Jan 23, 2004
  4. Vijay Kerji

    Window.Close Opens New Annoying Window

    Vijay Kerji, Dec 1, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    2,123
    Eliyahu Goldin
    Dec 1, 2004
  5. Sergei Shelukhin

    annoying features of VS IDE autoformatting

    Sergei Shelukhin, Mar 13, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    328
    Sergei Shelukhin
    Mar 14, 2005
Loading...

Share This Page