[Top][All Lists]

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

Re: [Axiom-math] What is the "+/" operator?

From: Ralf Hemmecke
Subject: Re: [Axiom-math] What is the "+/" operator?
Date: Wed, 23 May 2007 19:13:46 +0200
User-agent: Thunderbird (X11/20070326)

On 05/23/2007 06:50 PM, Bill Page wrote:
Quoting Martin Rubey <address@hidden>:

... Igor Khavkine writes:

Can someone explain this syntax? Looking at the Axiom .spad files,
I see that it has general usage +/[...some list construction...].

It is old syntax for reduce and should go away.

I very much agree. The reason is that one should give an initial value otherwise you might be surprised.

woodpecker:~/scratch>aldor -fx -laldor
Sum:  29
Prod: 0

But if you like the


syntax, you can actually define a similar things in Aldor. (I guess, SPAD would be just the same.)


#include "aldor"
#include "aldorio"

macro Z == Integer;

Pkg: with {
        /: ((Z, Z) -> Z, List Z) -> Z;
} == add {
        (f: (Z, Z) -> Z) / (l: List Z): Z == {
                empty? l => 0;
                f(first l, f/(rest l));

main(): () == {
        import from Pkg;
        l1: List Z := [2,4,6,8,3,5,1];
        sum: Z  := (+)/l1;
        prod: Z := (*)/l1;
        stdout << "Sum:  " << sum << newline;
        stdout << "Prod: " << prod << newline;


reply via email to

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