--* From DOOLEY%WATSON.vnet.ibm.com@yktvmv.watson.ibm.com  Thu Jan 20 11:20:09 1994
--* Received: from yktvmv.watson.ibm.com by leonardo.watson.ibm.com (AIX 3.2/UCB 5.64/4.03)
--*           id AA20323; Thu, 20 Jan 1994 11:20:09 -0500
--* X-External-Networks: yes
--* Received: from watson.vnet.ibm.com by yktvmv.watson.ibm.com (IBM VM SMTP V2R3)
--*    with BSMTP id 4507; Thu, 20 Jan 94 11:26:18 EST
--* Received: from YKTVMV by watson.vnet.ibm.com with "VAGENT.V1.0"
--*           id <A.DOOLEY.NOTE.VAGENT2.7805.Jan.20.11:26:15.-0500>
--*           for asbugs@watson; Thu, 20 Jan 94 11:26:17 -0500
--* Received: from YKTVMV by watson.vnet.ibm.com with "VAGENT.V1.0"
--*           id 7799; Thu, 20 Jan 1994 11:26:15 EST
--* Received: from matteo.watson.ibm.com by yktvmv.watson.ibm.com (IBM VM SMTP V2R3)
--*    with TCP; Thu, 20 Jan 94 11:26:14 EST
--* Received: by matteo.watson.ibm.com (AIX 3.2/UCB 5.64/920123)
--*           id AA23564; Thu, 20 Jan 1994 11:25:56 -0500
--* Date: Thu, 20 Jan 1994 11:25:56 -0500
--* From: dooley@matteo.watson.ibm.com (Sam Dooley)
--* Message-Id: <9401201625.AA23564@matteo.watson.ibm.com>
--* To: asbugs@watson.ibm.com
--* Subject: [3] genfoam bug in domain init ordering [dominit.as][v33.5[.5]]

--@ Fixed  by:  PI   Thu Mar 10 12:43:26 EST 1994 
--@ Tested by:  IdontKnow 
--@ Summary:    no more a bug 


-- 'asharp -F x -D Before dominit.as; dominit' fails
-- with an 'Illegal instruction' message (on the RS/6000)
-- since the initialization of f$D appears in the file-level
-- getter before the initialization of 'Conditional'.

-- When the getter for 'D' is called to get 'f', it tries
-- to get the defaults from 'Conditional', which hasn't yet
-- been initialized.

-- 'asharp -F x -D After dominit.as; dominit' prints '10', as expected.

#include "aslib"

macro {
	Bit		== Boolean;
	Ptr		== Pointer;
	Int		== SingleInteger;

	Nil S		== nil$Ptr pretend S;
	ptr x		== x @ % pretend Ptr;
}

import {
	Ptr;
	Int;
}

(i: Int) / (j: Int) : Int == {
	(a,b) := divide(i, j);
	a;
}

macro CDef == {
	C(n: Int, k: Int): Int == {
		import D;
		f(n)/(f(k) * f(n-k));
	}
}

#if Before
CDef
#endif

D: Conditional with {
	f: Int -> Int
}
== add {
	f (n: Int) : Int == if n = 0 then 1 else n * f(n-1);

	-- These are here just to make D a Conditional.
	sample : % == Nil(%);
	(p: %) = (q: %) : Bit == ptr p = ptr q;
	apply (p: OutPort, q: %) : OutPort == p ptr q;
	test (p: %) : Bit == test ptr p;
}

#if After
CDef
#endif

print(C(5, 3))()
 
