Re: Declaring a Function Before it is used

new topic     » goto parent     » topic index » view thread      » older message » newer message

----- Original Message ----- 
From: "Michelle Rogers" <michellerogers at bellsouth.net>
To: <EUforum at topica.com>
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

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu