Perl

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • Idea for making @, %, $ optional

    5 answers - 2526 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    I have thought of an interesting idea that may allow Perl 6 to make the
    $, @, and % optional on many uses of variables. This involves simply
    extending the function namespace to include all kinds of structures, and
    thus the function namespace does not require symbols, they are optional.
    The intention here is not to eliminate $, @, % and friends, just make
    them optional! I believe people should be able to make the choice as to
    which way to do things, we should give the programmer as much freedom
    and as any many ways to do things as possible, not constrain them but
    empower and free them from restrictions.
    Also, a goal I have tried to follow here is to implement this feature
    without affecting the existing usage grammar and rules of the Perl 6
    language at all. This is a good goal i believe, my intention is just for
    this to be an additional extension to Perl 6, not change its existing
    grammar and parsing rules at all, just expand upon it. Perl 6 is a great
    language and I like what has done so far. This is not an attempt to
    change what has already been defined, but rather provide an additional
    usage.
    These are just some initial ideas, they may be able to be improved upon,
    or benefit from refinement.
    **Subroutines
    sub hello {
    print "hello!\n";
    }
    Arrays
    #Define
    array hello=("1", "2", 3");
    #in Array context:
    @array=&array; #or
    @array=array array;
    #in Scalar context:
    $element=array[1]; #or
    $element=scalar array[1];
    Hashs
    #Define
    hash hash1=(hello=>"hello1", hello2=>"hello2");
    #In hash context=
    %hash2=&hash1; # or
    %hash2=hash hash1;
    #scalar context
    $hello=hash{hello}; # or
    $hello=scalar hello{hello};
    Scalars
    #Define
    scalar hello="hello";
    #Scalar context
    $hello=hello; # or
    $hello=scalar hello;
    References
    #Make reference
    scalar ref=\&hash; #or
    scalar ref=mkref &hash; #or
    scalar ref=mkref hash hash;
    #Dereference:
    #Every ampersand after the initial one attempts to deference the
    # one level of referncing:
    %hash=&&ref;
    # THis would unwrap a reference in a reference
    %hash=&&&ref;
    # Dereference a reference in a hash
    %hash=&&hash{ref};
    #or
    # A deref keyword for convenience:
    %hash=deref ref; #or
    %hash=hash scalar ref; #or
    %hash=hash hash ref;
    This is just an initial sketch, it may need or benefit from refinement.
  • No.1 | | 1149 bytes | |

    Millsa Erlas wrote:
    I have thought of an interesting idea that may allow Perl 6 to make the
    $, @, and % optional on many uses of variables. This involves simply
    extending the function namespace to include all kinds of structures, and
    thus the function namespace does not require symbols, they are optional.

    Also, a goal I have tried to follow here is to implement this feature
    without affecting the existing usage grammar and rules of the Perl 6
    language at all. This is a good goal i believe, my intention is just for
    this to be an additional extension to Perl 6, not change its existing
    grammar and parsing rules at all, just expand upon it. Perl 6 is a great
    language and I like what has done so far. This is not an attempt to
    change what has already been defined, but rather provide an additional
    usage.

    In that case, you should be looking into how to make it a pragmata,
    rather then pushing the idea on perl6-language. It shouldn't be too
    hard -- a matter of using the equivalent of perl5's UNIVERSAL::AUTLAD,
    and the UTER:: scope.

    James Mastros,
    theorbtwo
  • No.2 | | 1603 bytes | |

    James Mastros wrote:
    Millsa Erlas wrote:

    >>I have thought of an interesting idea that may allow Perl 6 to make the
    >>$, @, and % optional on many uses of variables. This involves simply
    >>extending the function namespace to include all kinds of structures, and
    >>thus the function namespace does not require symbols, they are optional.
    >>
    >>Also, a goal I have tried to follow here is to implement this feature
    >>without affecting the existing usage grammar and rules of the Perl 6
    >>language at all. This is a good goal i believe, my intention is just for
    >>this to be an additional extension to Perl 6, not change its existing
    >>grammar and parsing rules at all, just expand upon it. Perl 6 is a great
    >>language and I like what has done so far. This is not an attempt to
    >>change what has already been defined, but rather provide an additional
    >>usage.


    In that case, you should be looking into how to make it a pragmata,
    rather then pushing the idea on perl6-language. It shouldn't be too
    hard -- a matter of using the equivalent of perl5's UNIVERSAL::AUTLAD,
    and the UTER:: scope.

    James Mastros,
    theorbtwo

    Does this allow the grammer rules of the language to be changed so that
    this could be implemented? How does this work?

    Making this feature something that could be implemented with a pragma
    would be a fine idea.
    Furthermore the idea I have had to
  • No.3 | | 1183 bytes | |

    6/3/05, Millsa Erlas <millueradfa (AT) yahoo (DOT) comwrote:
    Does this allow the grammer rules of the language to be changed so that
    this could be implemented? How does this work?

    Yes. In fact, one of the big goals of perl 6 is to allow people to
    mutate the grammar of the language.

    If you just want scalar sigilless variables, you might do something like this:

    grammar Sigilless;
    is Perl::Grammar;

    rule sigil () { $<super:= <SUPER::sigil
    { $<sigil= $<super><sigi}
    | <null
    { $<sigil= '$' }
    }

    module sigilless;
    sub import () {
    SHIFT { use grammar Sigilless }
    }

    (Where I use SHIFT, which I just learned about from Autrijus, to
    execute code in the caller's scope.)

    That seems the simplest hypothetical way. I'm not sure how that would
    play with the real grammar. We can hope it's that simple, but it will
    likely take a bit more work than that.

    This pretends that all sigilless variables are scalars, which might be
    the best way for sigilless to go anyway given Perl 6's reference
    semantics.

    Luke
  • No.4 | | 3554 bytes | |

    Austin Hastings wrote:

    James Mastros <james (AT) mastros (DOT) bizwrote:


    >>Millsa Erlas wrote:
    >>

    I have thought of an interesting idea that may allow Perl 6 to make
    >>
    >>the
    >>

    $, @, and % optional on many uses of variables. This involves
    >>
    >>simply
    >>

    extending the function namespace to include all kinds of
    >>
    >>structures, and
    >>

    thus the function namespace does not require symbols, they are
    >>
    >>optional.


    []


    >>In that case, you should be looking into how to make it a pragmata,
    >>rather then pushing the idea on perl6-language. It shouldn't be too
    >>hard -- a matter of using the equivalent of perl5's
    >>UNIVERSAL::AUTLAD,
    >>and the UTER:: scope.
    >>
    >> James Mastros,
    >>theorbtwo


    The fact that this keeps recurring on P6L is pretty indicative, I
    think, that a lot of people t value the ability to have an array,
    hash, and scalar of the same name quite so much as they regret the need
    to respecify the types of all variables every time re used.

    If s really that simple to do, then Im willing to bet ll be
    used early and often. Making it a part of and in fact planning
    to migrate perl in the direction of less useless line noise DES seem
    to me to be a valid task for -language.

    =Austin

    I believe that people should be given the choice as to whether to use $,
    @, or %, or not.My suggestion was one possible way to achieve making $,
    @, and % optional, while still allowing their use and not changing the
    existing perl 6 language. This is could be done by simply allowing hashs
    and arrays to be defined in the function namespace. The existing
    seperate array and hash namespaces would also be retatianed with their %
    and @ usage as well, giving people choice. I want very much to preserve
    peoples choice as to which way to do things and I do not want this
    suggestion implemented in a way if it takes away peoples right to use $,
    @ and %, or impacts Perl 6's existing grammer in other ways.

    of the reasons I suggest this idea, is indeed variables are very
    commonly used in many cases, in a program, and typing the prefix
    characters in my expierience at times is a bit of annoyance, especially
    since it requires a trip to the shift key. This is not a big problem
    with things that are seldom used in a language, but when it applies to
    something as commonly used as variables, it becomes more significant.
    Maybe its not a huge thing but it is a bit of annoyance at times to me.
    It may not be to other people thats why if people want to keep using $,
    @, And %, they should be able to, and I will still want to use them
    myself at times.

    I strongly believe in TIMTWTDI (There is more than one way to do it),
    which is one reason I like Perl, is that it gives people freedom, does
    not restrict them, and gives them flexibility and as many choices as
    possible to how to best accomplish something. I certianly hope Perl 6
    can continue, and even expand this.
  • No.5 | | 2985 bytes | |

    Millsa Erlas wrote:
    I have thought of an interesting idea that may allow Perl 6 to make the
    $, @, and % optional on many uses of variables. This involves simply
    extending the function namespace to include all kinds of structures, and
    thus the function namespace does not require symbols, they are optional.

    The intention here is not to eliminate $, @, % and friends, just make
    them optional! I believe people should be able to make the choice as to
    which way to do things, we should give the programmer as much freedom
    and as any many ways to do things as possible, not constrain them but
    empower and free them from restrictions.

    Also, a goal I have tried to follow here is to implement this feature
    without affecting the existing usage grammar and rules of the Perl 6
    language at all. This is a good goal i believe, my intention is just for
    this to be an additional extension to Perl 6, not change its existing
    grammar and parsing rules at all, just expand upon it. Perl 6 is a great
    language and I like what has done so far. This is not an attempt to
    change what has already been defined, but rather provide an additional
    usage.

    These are just some initial ideas, they may be able to be improved upon,
    or benefit from refinement.

    **Subroutines

    sub hello {
    print "hello!\n";
    }

    Arrays
    #Define
    array hello=("1", "2", 3");

    #in Array context:
    @array=&array; #or
    @array=array array;

    #in Scalar context:
    $element=array[1]; #or
    $element=scalar array[1];

    Hashs
    #Define
    hash hash1=(hello=>"hello1", hello2=>"hello2");

    #In hash context=
    %hash2=&hash1; # or
    %hash2=hash hash1;

    #scalar context
    $hello=hash{hello}; # or
    $hello=scalar hello{hello};

    Scalars

    #Define
    scalar hello="hello";

    #Scalar context

    $hello=hello; # or
    $hello=scalar hello;

    References
    #Make reference
    scalar ref=\&hash; #or
    scalar ref=mkref &hash; #or
    scalar ref=mkref hash hash;

    #Dereference:

    #Every ampersand after the initial one attempts to deference the
    # one level of referncing:
    %hash=&&ref;
    # THis would unwrap a reference in a reference
    %hash=&&&ref;

    # Dereference a reference in a hash
    %hash=&&hash{ref};

    #or
    # A deref keyword for convenience:
    %hash=deref ref; #or
    %hash=hash scalar ref; #or
    %hash=hash hash ref;

    This is just an initial sketch, it may need or benefit from refinement.

    I think that implementing the features I have described above as a
    module of some sort rather than include it in core would be very
    reasonable and acceptable, I am in fact looking into ways of doing this.

    @, $, and % does indeed have its advantages and I should continue to
    remain avialable. I think some sort of module is a good route to go for
    offering alternative grammer, so I am happy with this solution.

Re: Idea for making @, %, $ optional


max 4000 letters.
Your nickname that display:
In order to stop the spam: 7 + 6 =
QUESTION ON "Perl"

EMSDN.COM