Re: "Forward" function declarations?
- Posted by Michael Nelson <MichaelANelson at WORLDNET.ATT.NET> Feb 08, 2001
- 450 views
----- Original Message ----- From: "Ted Fines" <fines at macalester.edu> To: <EUforum at topica.com> Sent: Thursday, February 08, 2001 7:45 AM Subject: "Forward" function declarations? > I need to do the "C" equivalent of a "forward" function declaration in > Euphoria. Can this be done? > Not directly. A forward reference is illegal in Euphoria: funcion foo(object x) integer z z=bar(x) --syntax error "bar" not defined return z+2 end function function bar(object y) if atom(y) return -1 else return length(y) end function printf(1,"%d",foo({1,2,3})) and there is no way to declare a routine before it is defined (as there is in C). Instead Euphoria uses routine_id(): integer bar_ID --bar_ID must be defined before foo() funcion foo(object x) integer z z=call_func(bar_ID,{x}) return z+2 end function function bar(object y) if atom(y) return -1 else return length(y) end function bar_ID=routine_id("bar") -- routine_id() must be used after bar() printf(1,"%d",foo({1,2,3})) Now this works as foo() can "see" bar_ID and bar_ID is assigned a value before foo() is called. -- Mike Nelson