in reply to Re^6: Two more Features Perl 5 Maybe Needs
in thread Five Features Perl 5 Needs Now

Don't know what you mean ... all my examples were parenthesized so precedence problems shouldn't occur !?!

I mean exactly:

Actually it's practically impossible to implement this with a simple code-filter, (see my first approach) because one can't tell by static parsing where the dereferencing ends ( here the last array-index ) and where to put the closing curly.

In other words, you're arguing to add more syntax to Perl, syntax that's difficult to type, to make the simple cases easy (except that they're more difficult to type) -- except that the syntax doesn't actually make the difficult cases any easier, because either it's ambiguous to parse because of the precedence and associativity of the new dereferencing operator, or you enforce a fixed amount of dereferencing and have to use the existing syntax to isolate and disambiguate the reference.

I won't say that it's impossible to get this to work, but it's going to be very difficult, and the exceptions are probably going to be difficult to understand, and no one's going to use it.

  • Comment on Re^7: Two more Features Perl 5 Maybe Needs

Replies are listed 'Best First'.
Re^8: Two more Features Perl 5 Maybe Needs
by LanX (Saint) on Dec 24, 2008 at 16:13 UTC
    
              Contrary to Perl 6 my approach is still compatible, because you can transform them back into standard Perl 5.
    
          ... until the first time you run into a precedence problem, for example with hash or list slices.
    
        Don't know what you mean ... all my examples were parenthesized so precedence problems shouldn't occur !?!
    
    I mean exactly:
    
        Actually it's practically impossible to implement this with a simple code-filter,...
    

    My point is that the proposed transformation rules are well-defined and backwards-compatible within perl5, contrary to perl6. One can always take code with new sigils and transform it back into normal sigils and parentheses to run it with an old perl 5 version.

    The implementation of these rules with static code filters can of course only be - like I already said - an ersatz to demonstrate the concept. This is certainly not meant for production.

    For the realisation: If it's not possible to extend the perl parser accordingly, a real macro system is needed (which is N° 8 on my wishlist) That means changing the code after compilation but before execution!

    >In other words, you're arguing to add more syntax to Perl, syntax that's difficult to type, to make the simple cases easy

    well I think most languages, including perl6, consider it easier that arrays are primarily references and only transformed into a list if it's indicated by a modifier.

    Maybe I should express these transformation rules with plain words instead of code, to make them clearer:

    1. €arr is a scalar $arr which holds a array_ref
    2. €arr[][] can be dereferenced without any arrow-operator, that means is identical to $arr->[]->[].
    3. Dereferencing of €arr has higher precedence than transformation to an array:  @€arr[][] == @{€arr[][]}
    4. In situations where the parser wants an array to follow (*), e.g. forced by prototype (\@) , €arr is passed directly. That means push €arr,expr is identical to push @$arr,expr
    I think all perl-experts (like you are), might think it's getting more complicated this way, but I bet most beginners will consider it much easier and experts will adapt easily. Because it's huffman-coded, the frequent use cases are getting much easier, and the others don't get more complicated! And IMHO anyway there is no need anymore to use @arr or %hash if one can seemlesly use references!

    Cheers Rolf

    (*) more precisely in these situations an @ has to follow but only the reference is passed.

      To help you to get a feeling for what I mean, try this uncompleted(!) codefilter, which is only a hack(!) under construction ...

      XSigils.pm
      #!/usr/bin/perl sub ar2list ($) { return @{ $_[0] }; } sub push_aref ($@) { CORE::push( @{+shift} , @_ ); } package XSigils; use Filter::Simple; FILTER { warn "\n\n\n --- Before Transformation: \n$_"; s{ push (\s|\() (\s*) €} {push_aref$1$2€}xg; s{ \@ \s* €} {ar2list €}xg; # 2array s{ €(\w+)\[ } {\$$1->\[}xg; # dereference s{ €(\w+) } {\$$1}xg; # simple scalar warn "\n\n\n --- After Transformation: \n$_"; warn "\n\n\n --- Code execution!\n"; }; 1;
      tstXSigils.pl
      #!/usr/bin/perl use XSigils; $\="\n"; €arr=[1..3]; push €arr,4,5; print @€arr;
      OUTPUT
      --- Before Transformation: $\="\n"; €arr=[1..3]; push €arr,4,5; print @€arr; # (*) --- After Transformation: $\="\n"; $arr=[1..3]; push_aref $arr,4,5; print ar2list $arr; --- Code execution! 12345

      Cheers Rolf

      UPDATE: (*) of course that's more complicated than print @arr, but I wonder how perl6 intends to handle this case ... ?

        I think it's time for you to let it go. It's not just your own time you're wasting.