in reply to Perl 6 - Operator renaming

my most expected favourite is meta-operator []

for example:

[*] 1..100; # applies '*' to all list; so result is 100! [//] @a; # first defined [+] @b; # sum of all

Not operator, but very close - junctions are promising to be very convenient:

if $a eq "foo" | "bar" | "fluffy" { # do this stuff }

Replies are listed 'Best First'.
Re^2: Perl 6 - Operator renaming
by Anonymous Monk on Sep 02, 2005 at 19:43 UTC
    my most expected favourite is meta-operator []
    Is that just syntatic sugar for fold?
      Yes and no. The basic definition of [op] in Perl 6 is syntactic rather than semantic, so it will do either foldl or foldr depending on the syntactic associativity of the operator in question. But the syntactic definition goes a little beyond that, insofar as it can be applied to context-dependent syntactic operators that have no fixed run-time meaning, such as [;] or [,]. Since the meanings of ; and , depend on syntactic context, so do the meanings of [;] and [,].

      Furthermore, it can be applied to operators that are neither left nor right-associative, such as the various list-associative operators, which in Perl 6 includes the comparison operators. So you can write

      [<] @array
      to mean
      @array[0] < @array[1] < @array[2] ...
      which will tell you if the array is monotonically increasing without having to do strange semantic contortions to separate value from success (see Icon).

      There will still be need for underlying foldl and foldr equivalents to force folding "against the grain", but for most purposes (including educational and visual), the [op] form is more accessible, I think.