Re: Declaring a Function Before it is used
- Posted by Derek Parnell <ddparnell at bigpond.com> Oct 29, 2003
- 383 views
----- Original Message ----- From: "Michelle Rogers" <michellerogers at bellsouth.net> To: <EUforum at topica.com> Sent: Wednesday, October 29, 2003 10:09 AM Subject: Re: Declaring a Function Before it is used > > > wait a sec...i thought this language was supposed to be EASIER to use...then > why would you have to go through all of this for a simple "declare a > function before it's used"? I 100% agree. I believe that the author of Euphoria regards forward referencing as a bad programming practice and therefore will not support it. > ----- Original Message ----- > From: "Derek Parnell" <ddparnell at bigpond.com> > To: <EUforum at topica.com> > Sent: Tuesday, October 28, 2003 7:10 AM > Subject: Re: Declaring a Function Before it is used > > > > ----- Original Message ----- > > From: "Michelle Rogers" <michellerogers at bellsouth.net> > > To: <EUforum at topica.com> > > Sent: Tuesday, October 28, 2003 10:06 PM > > Subject: Declaring a Function Before it is used > > > > > > > Also, can anyone tell me if there is a way to declare a function before > it > > > is used. > > > > You can't, damn it! This is the thing I most want in Euphoria, but the > author is philosophically against it. > > > > > If not, how do you handle things like: > > > Run Function A, which calls Function B > > > Function B calls Function C > > > If statement then > > > Function C calls Function D > > > else > > > Function C calls Function A > > > end if > > > > > > This seems impossible to handle if you can't declare Function A ahead of > > > time, because you can't move it ahead of Function C to solve the > problem, > > > since that causes a problem of not being able to call Functions B and C > from > > > Function A > > > > > > > Welcome to the wonderful world of 'routine_id()'. > > > > The function 'routine_id()' returns an index to a routine, and the > routines 'call_proc()' and 'call_func()' can use this index to invoke the > routine indirectly. Here is an example... > > > > -- This need to be near the front of the file. > > integer r_FuncA, r_FuncB, r_FuncC, r_FuncD > > > > function FuncA() > > x = call_func(r_FuncB,{}) > > end function > > > > function FuncB() > > x = call_func(r_FuncC,{}) > > end function > > > > function FuncC() > > if statement then > > x = call_func(r_FuncD,{}) > > else > > x = call_func(r)FuncA,{}) > > end if > > end function > > > > function FuncD() > > . . . > > end function > > > > -- These need to be after the routines they are referring to. > > r_FuncA = routine_id("FuncA") -- Notice the routine name is in a string. > > r_FuncB = routine_id("FuncB") > > r_FuncC = routine_id("FuncC") > > r_FuncD = routine_id("FuncD") > > > > > > -- > > Derek > > > > > > TOPICA - Start your own email discussion group. FREE! > > > > > > > TOPICA - Start your own email discussion group. FREE! > >