Re: Declaring a Function Before it is used

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

On Wed, 29 Oct 2003 23:05:36 +1100, Derek Parnell
<ddparnell at bigpond.com> wrote:

>   x = foo(1, 2.4, "abc")
>   . . .
>   function foo(sequence a, integer b, integer c)

You are aware that even if those lines are the other way round, RDS Eu
does not perform any type checking whatsoever at parse/compile time. 
I don't think this is a problem, btw, I'm just saying that forward ref
wouldn' "lose" type-checking, since there is none done in the first
place. You can prove this with:
	function foo(sequence a, integer b, integer c) 
		return 1
	end function
	function bar()
		return foo(1, 2.4, "abc")
	end function
	puts(1,"no error yet\n")
	if getc(0) then end if
	?bar()	-- this will still crash, of course

Theoretically, forward referencing need be no different to 'else'
handling, the only thing needed is new error messages:

	fred(1,2,3,4)
	...
	procedure fred(integer a, integer b, integer c)
										  ^
error: procedure previously used with 4 parameters 

and an undefined routine message like the type check error above, if
you try to actually execute the call before the routine is defined, or
at the end of the program.

>One really annoying aspect of routine_id() is that it doesn't do forward
>referencing either.
Yup
>If it did, it would simplify libraries like Win32lib and Diamond.
>We could then test for the existance of user-written routines
> - in win32lib's case, I could test for "onPaint_MyWindow" etc.
> so the user didn't have to do a setHandler() at runtime.
Have you tried:

include win32lib.ew
<user code>

include win32rtn.ew
WinMain(Main,Normal)

where win32rtn.ew is something like:

-- code starts --
function rid(sequence name)
	return routine_id(name)
end function

w32Init(routine_id("rid"))
-- code ends --

You might want to allow daisy-chaining of several copies of such a
routine, to prevent all the "onPaint_MyWindow" having to be global.
(In which case function rid()'s would have to be hand-coded.)

Pete

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

Search



Quick Links

User menu

Not signed in.

Misc Menu