1. "Forward" function declarations?
- Posted by Ted Fines <fines at macalester.edu> Feb 08, 2001
- 468 views
I need to do the "C" equivalent of a "forward" function declaration in Euphoria. Can this be done?
2. Re: "Forward" function declarations?
- Posted by Michael Nelson <MichaelANelson at WORLDNET.ATT.NET> Feb 08, 2001
- 451 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
3. Re: "Forward" function declarations?
- Posted by Kat <gertie at PELL.NET> Feb 08, 2001
- 435 views
On 8 Feb 2001, at 10:13, Michael Nelson wrote: > > ----- 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. This is another example of where the interpreter can be made smarter: If the procedure hasn't been declared yet, look further into the code for it!! I have seen some programs wherein everything has been routine_id()'d, and all procedure and function calls are to the routine_id . The interpreter could be doing this as a default, and making the order of precedence irrelevant. Kat
4. Re: "Forward" function declarations?
- Posted by Euman <euman at bellsouth.net> Feb 08, 2001
- 455 views
</snip> constant TRUE = 1, FALSE = 0 sequence types, handles, rps global procedure add_function (object handle, integer rp) integer pos pos = find (handle, handles) if pos then types[pos] = TRUE -- It does return something rps[pos] = rp else handles = append(handles, handle) types = append(types, TRUE) rps = append(rps, TRUE) end if end procedure global procedure add_procedure (object handle, integer rp) integer pos pos = find (handle, handles) if pos then types[pos] = FALSE -- It does return something rps[pos] = rp else handles = append(handles, handle) types = append(types, FALSE) rps = append(rps, FALSE) end if end procedure global function call_routine (object handle, sequence arg) integer pos pos = find (handle, handles) if pos then if types[pos] then return {TRUE, call_func (rps[pos], arg)} else call_proc (rps[pos], arg) return {TRUE} end if else return {FALSE} end if end function <snip\> I think Kat might have been refering to this. Euman ----- Original Message ----- From: "Kat" <gertie at PELL.NET> To: <EUforum at topica.com> Sent: Thursday, February 08, 2001 13:34 Subject: Re: "Forward" function declarations? > On 8 Feb 2001, at 10:13, Michael Nelson wrote: > > > > > ----- 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. > > This is another example of where the interpreter can be made smarter: If the procedure > hasn't been declared yet, look further into the code for it!! I have seen some programs > wherein everything has been routine_id()'d, and all procedure and function calls are to > the routine_id . The interpreter could be doing this as a default, and making the order > of precedence irrelevant. > > Kat > >
5. Re: "Forward" function declarations?
- Posted by Derek Parnell <ddparnell at bigpond.com> Feb 08, 2001
- 453 views
Hi Kat, > This is another example of where the interpreter can be made smarter: If the procedure > hasn't been declared yet, look further into the code for it!! RDS is aware of this idea and acknowledges that technically it is not all that difficult to do, but I believe that RDS won't do it because it is against their philosophy. ------ Derek Parnell Melbourne, Australia (Vote [1] The Cheshire Cat for Internet Mascot)