lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] Why have all relational operators for containers?


From: Vadim Zeitlin
Subject: Re: [lmi] Why have all relational operators for containers?
Date: Wed, 24 Mar 2021 23:06:26 +0100

[this is completely OT, please feel free to skip it if you're busy]

On Wed, 24 Mar 2021 15:06:04 +0000 Greg Chicares <gchicares@sbcglobal.net> 
wrote:

GC> > C++ just doesn't provide vector operations.
GC> 
GC> That almost makes me long for 'extern "FORTRAN"'.
GC> 
GC> > What you really want is
GC> > Raku (née Perl 6)
GC> 
GC> Well, okay, 'extern "Raku"'.

 FWIW Raku does provide "extern C++". Or at least C, but as this is done in
https://github.com/FROGGS/p6-Inline-C by running (transparently, i.e. at
compilation time) the C compiler, it should be easy to generalize it to C++
too. This is not one of the features of Raku I really expect to ever use,
but it's still fun to use a language supporting it.

GC> [...snip examples...]
GC> >  Raku operator composability is really very aesthetically pleasant, if
GC> > nothing else.
GC> 
GC> It's much more. With a rich set of operators that are composable,
GC> we can write code in a terse way the precludes all sorts of errors.

 Yes. Note that composability in Raku exists in all kinds, i.e. you have
hyper-operators (4 version of them, as you can use either » or « on either
direction to indicate whether the shorter list/array should be extended)
but also

1. Can combine any operator with "=", not just "+" or "-", i.e. you could
   also also write

        > $x1 max= $x0 # increase $x1 to $x0
        [4 5 6]

2. Reduction meta-operator [...] can be used with any other operator too:

        > [max] 4,5,6 # to use $x0 you'd have to flatten it: "|$x0"
        6

   Of course, this is not very useful with max which is defined for any
   number of arguments anyhow and you could just do

        > max 4,5,6 # or max |$x0
        6

   anyhow, but [+], [*] etc are pretty useful.

   It also can return all the intermediate results, which is slightly more
   useful with max:

        > [\max] |$x0
        (4 5 6)
        > [\max] 6,5,4 # just for illustration
        (6 6 6)

3. Cross and zip metaoperators implement Cartesian and direct product using
   any operator:

        > (4,5,6) Xmax (3,9)
        (4 9 5 9 6 9)
        > (4,5,6) Zmax (3,9)
        (4 9)

   (again, using "max" here is a bit unusual perhaps, but it does work and
    for all I know this could be a common operation for an APL programmer).

 Sorry for my exuberance, but this is a part of Raku that I really like
(spoiler: there are other parts that I like even more!).

VZ

Attachment: pgpYoMAbZFRs9.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]