Re: Variable declarations

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

Jim Hendricks wrote:
> 
> 
> Just started working with Euphoria a couple of days ago, but have
> been professionally programming for 20+ years.
> 
> I love the simplicity of Euphoria!  Am porting an existing app over
> as my way of getting my feet wet.
> 
> Haven't dug in deep yet so this issue may have already been discussed,
> or may be in the manual and I just missed it.
> 
> The manual states that variables must be declared before they are used,
> what I didn't see is that at least in a proc/func definition, all the
> declarations must come first ( this is just anecdotal and I may be missing
> something stupid )
> 
> Here's an example:
> 
> }}}
<eucode>
> procedure test()
>   atom myatom
>   myatom = 1
>   sequence myseq
>   myseq = "test"
> end procedure
> </eucode>
{{{

> 
> This is just sample code, I tried running it real quick and it seems to
> demonstrate the error I was receiving.  On line: "sequence myseq" I 
> get the exception: Syntax error - expected to see possibly 'end', not 
> a type .  If I trade this line with the previous line, all is cool.
> 
> This seems to suggest that at least within and procedure or function
> definition all the declarations must be made prior to any other code.
> 
> Is this correct?  Is it documented behavior?  It's not a problem for me
> since enforcing declarations before code results in cleaner and easier
> to read code, I just thought that if this was not documented, it would
> go a long ways toward helping out the newbies!


Yes, variables inside routines must be declared prior to the first 
executable statement in that routine. It is documented under the 
heading 'scope'...

"Variable declarations inside a subroutine must all appear 
at the beginning, before the executable statements of the subroutine."

-- 
Derek Parnell
Melbourne, Australia

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

Search



Quick Links

User menu

Not signed in.

Misc Menu