human nature of perl (new operators etc)

Discussion in 'Perl Misc' started by I H H, Nov 11, 2004.

  1. I H H

    I H H Guest

    Hello,

    perl's syntax is what it is (as I undertood correctly) because it was
    supposed to be like human languages.
    Meaning a word or a phrase has context bind meaning. If context changes, the
    meaning changes too.
    Should there be more human nature properties in perl?

    Could these be useful? At least might make scripting even more faster.

    Division operator in string context would be like 'split':

    @cols=split(/$expression/,$line); <=> @cols=$line/$expression;

    ---
    open(F,$file);
    @lines=<F>;
    close(F);

    <=>

    @lines<$file>\o /\n;

    ---
    if($x>$y){do_something $arr[$x];} <=> $arr[(if($x>$y))] cond returning
    values that fill it.


    ---

    anyone else having crazy ideas like these?
     
    I H H, Nov 11, 2004
    #1
    1. Advertising

  2. On Thu, 11 Nov 2004 10:37:10 +0000, I H H wrote:

    > perl's syntax is what it is (as I undertood correctly) because it was
    > supposed to be like human languages.
    > Meaning a word or a phrase has context bind meaning. If context changes, the
    > meaning changes too.
    > Should there be more human nature properties in perl?


    perl has enough ways to do it ... maybe *too* many ways. It gets to a
    point that one has to say "enough is enough".

    > Could these be useful? At least might make scripting even more faster.
    >
    > Division operator in string context would be like 'split':

    <snip>

    IMHO, 'split' works fine the way it is. "If it ain't broke, don't fix it" :)

    > anyone else having crazy ideas like these?


    Yes, but I keep these ideas to myself ... people already think I'm crazy
    and I don't want to give them any more ammunition :)

    In all seriousness ... if you want to experiment with "wild and crazy"
    ways to do it, you could develop your own class(es) and see how much
    effort goes into doing it different ways. For example: you could write
    your own class to overload the '<=>' (or some other) operator to do what
    you propose.

    HTH

    Jim
     
    James Willmore, Nov 11, 2004
    #2
    1. Advertising

  3. "I H H" <> writes:
    > Could these be useful? At least might make scripting even more faster.
    >
    > Division operator in string context would be like 'split':
    >
    > @cols=split(/$expression/,$line); <=> @cols=$line/$expression;


    But wouldn't you still want "424242" / "42" to produce 10101?
     
    Arndt Jonasson, Nov 11, 2004
    #3
  4. I H H

    Tore Aursand Guest

    On Thu, 11 Nov 2004 10:37:10 +0000, I H H wrote:
    > Division operator in string context would be like 'split':
    >
    > @cols=split(/$expression/,$line); <=> @cols=$line/$expression;


    That would fail when you need to evaluate this expression, for instance;

    "100" / "10"

    Do you want to split on '10', or do you want to divide by ten? I think
    'split()' is nice as it is.

    > open(F,$file);
    > @lines=<F>;
    > close(F);
    >
    > <=>
    >
    > @lines<$file>\o /\n;


    You could always have a "Misc" module in hand, as I do;

    my @lines = read_file( $file );

    One other approach is to write a filter (using one of the Filter modules)
    to do what you want.

    > anyone else having crazy ideas like these?


    All the time, but I tend to keep them for myself. I don't want one those
    white, long-sleeved shirts. :)


    --
    Tore Aursand <>
    "To cease smoking is the easiset thing I ever did. I ought to know,
    I've done it a thousand times." (Mark Twain)
     
    Tore Aursand, Nov 11, 2004
    #4
  5. I H H

    Guest

    "I H H" <> wrote:
    > Hello,
    >
    > perl's syntax is what it is (as I undertood correctly) because it was
    > supposed to be like human languages.
    > Meaning a word or a phrase has context bind meaning. If context changes,
    > the meaning changes too.
    > Should there be more human nature properties in perl?
    >
    > Could these be useful? At least might make scripting even more faster.
    >
    > Division operator in string context would be like 'split':


    To the small extent that there is such a thing as "string context"
    in Perl, that context is provided by the operator. The operator
    can't be both dependent on and the source of this "context".



    >
    > @cols=split(/$expression/,$line); <=> @cols=$line/$expression;
    >
    > ---
    > open(F,$file);
    > @lines=<F>;
    > close(F);
    >
    > <=>
    >
    > @lines<$file>\o /\n;


    I'm not sure I understand what you are getting at here.

    > ---
    > if($x>$y){do_something $arr[$x];} <=> $arr[(if($x>$y))] cond returning
    > values that fill it.


    I've thought there should be some kind of defined_and or exists_and.

    It would short-circuit and return undef if not
    defined or exists, and would evaluate to the value of its argument
    otherwise.

    if (exists $h{$j}{$k}{L}{M}{$n}{$o}{P} and
    $h{$j}{$k}{L}{M}{$n}{$o}{P}==7)...

    if (exists_and $h{$j}{$k}{L}{M}{$n}{$o}{P} ==7 ) ...

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
     
    , Nov 11, 2004
    #5
  6. I H H

    Ben Morrow Guest

    Quoth "I H H" <>:
    > Hello,
    >
    > perl's syntax is what it is (as I undertood correctly) because it was
    > supposed to be like human languages.
    > Meaning a word or a phrase has context bind meaning. If context changes, the
    > meaning changes too.
    > Should there be more human nature properties in perl?
    >
    > Could these be useful? At least might make scripting even more faster.
    >
    > Division operator in string context would be like 'split':


    Larry has a rule-of-thumb for language design: either have polymorphic
    operators or polymorphic values. Trying to have both leads to insoluble
    ambiguities, where you can't tell what a given operation will actually
    do. Consider if Perl had only one ==, which did for both strings and
    numbers: which comparison would

    $a = "a";
    $b = 2;
    $a == b;

    perform, and how would you choose the other?

    Ben

    --
    It will be seen that the Erwhonians are a meek and long-suffering people,
    easily led by the nose, and quick to offer up common sense at the shrine of
    logic, when a philosopher convinces them that their institutions are not based
    on the strictest morality. [Samuel Butler, paraphrased]
     
    Ben Morrow, Nov 11, 2004
    #6
  7. I H H

    Peter Wyzl Guest

    <> wrote in message
    news:20041111171442.799$...
    > "I H H" <> wrote:


    ..snip.

    >> ---
    >> open(F,$file);
    >> @lines=<F>;
    >> close(F);
    >>
    >> <=>
    >>
    >> @lines<$file>\o /\n;

    >
    > I'm not sure I understand what you are getting at here.


    I think he meant that the <> operator could have a modifier '\o' which
    automatically handled the open and close part of the standard file read,
    with an optional argument which specified the default value for $/

    I think....

    :)

    --
    Wyzelli
    print 'Therefore, I am';
     
    Peter Wyzl, Nov 12, 2004
    #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. Xah Lee
    Replies:
    14
    Views:
    988
    Michele Dondi
    Jan 27, 2004
  2. bintom
    Replies:
    10
    Views:
    697
    James Kanze
    May 11, 2008
  3. Kevin Walzer

    Re: PIL (etc etc etc) on OS X

    Kevin Walzer, Aug 1, 2008, in forum: Python
    Replies:
    4
    Views:
    451
    Fredrik Lundh
    Aug 13, 2008
  4. Xah Lee
    Replies:
    13
    Views:
    218
    Michele Dondi
    Jan 27, 2004
  5. Xah Lee
    Replies:
    14
    Views:
    224
    Michele Dondi
    Jan 27, 2004
Loading...

Share This Page