--* From postmaster%watson.vnet.ibm.com@yktvmv.watson.ibm.com  Fri Jun 10 13:38:51 1994
--* Received: from yktvmv-ob.watson.ibm.com by asharp.watson.ibm.com (AIX 3.2/UCB 5.64/930311)
--*           id AA20866; Fri, 10 Jun 1994 13:38:51 -0400
--* Received: from watson.vnet.ibm.com by yktvmv.watson.ibm.com (IBM VM SMTP V2R3)
--*    with BSMTP id 5023; Fri, 10 Jun 94 13:38:52 EDT
--* Received: from YKTVMV by watson.vnet.ibm.com with "VAGENT.V1.0"
--*           id <A.USER2.NOTE.YKTVMV.5881.Jun.10.13:38:51.-0400>
--*           for asbugs@watson; Fri, 10 Jun 94 13:38:52 -0400
--* Received: from cesl.rutgers.edu by watson.ibm.com (IBM VM SMTP V2R3) with TCP;
--*    Fri, 10 Jun 94 13:38:51 EDT
--* Received: by cesl.rutgers.edu (5.59/SMI4.0/RU1.5/3.08)
--* 	id AA21788; Fri, 10 Jun 94 13:38:48 EDT
--* Date: Fri, 10 Jun 94 13:38:48 EDT
--* From: user2@cesl.rutgers.edu (Chris Whatley)
--* Message-Id: <9406101738.AA21788@cesl.rutgers.edu>
--* To: asbugs@watson.ibm.com
--* Subject: [5] segv [ex08.as][A# version 0.35.6 for SPARC [=] (debug version)]

--@ Fixed  by:  SSD   Tue Nov 8 11:54:20 EST 1994 
--@ Tested by:  none 
--@ Summary:    Not a bug. The user's program exhibits a runtime error in using generators. 

-- Example 8.  Function applied to a generator.

#include "aslib"

import from Integer, Segment Integer, List Integer;

I ==> Integer;

-- (a) Write an infix function '/' which takes a binary function f
--     on integers as its left argument, and a generator g of integers
--     as its right argument, and applies f to the integers given by g.


(f: (I, I) -> I) / (x: Generator I) : I == {
	for i in x repeat
		m:=f(i,f/(j for j in rest [x]));
	m;
}

z := (+)/(i*(i+1) for i in 1..100);
print("sum(i*(i+1)) = ")(z)();


-- (b) Print the sum of the squares of the numbers from 1 to 100.

-- (c) Use '/' to implement sum and factorial for generators of integers.
 
