Re: forward reference

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

Bernie Ryan wrote:
> 
> 
> When a user wants to create a forward reference in Euphoria;
> 
> why can't the user give a description of a function/procedure
> 
> at the top of their program.
> 
> }}}
<eucode>
> 
> function foo(sequence bar) end function
> 
> </eucode>
{{{

> 
> Then the scanner could create a dummy entry in the symbol table
> 
> as a holding place and target for any forward reference.
> 
> When this function name is encountered and there is code between the ')'
> 
> and 'end' tokens then the symbol table entry could be modified into
> 
> a real symbol table entry.
> 
> This could be done without having to change to a multipass scanner.
> 
> Could this be done ?
>    
> Bernie


Absolutely. It has already been implemented in CChris' AE interpreter using
this syntax:
forward function foo(sequence bar)


However, although good, this is still not ideal because:

1) the user has to add this extra line whenever they think a new routine
might be forward.

2) locals override globals so a routine (near the end of a file) that is
promoted to "forward" this way could unknowingly override a global of the
same name that is referenced earlier in the file. Whereas, normal routines
will only override globals from their declaration position.

3) it doesn't solve the issue of references in mutually including files
unless you're willing to manage literally truckloads of global forward
declarations.

In Orac, routine calls can be made anywhere inside a file and outside a file
when, say, mutually including files exist. It can do this because Orac is a
multi-pass system. Until Euphoria becomes the same, this problem of forward
references will persist. Everyone knows it but hardly anyone talks about it.
Forward references are one of the most important improvements that could be
made to the language but it would require rewriting fundamental parts of the
parser.

Who can save us?


regards,
Mike

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

Search



Quick Links

User menu

Not signed in.

Misc Menu