variable declarations and scope

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, LCMark

Locked
monte
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1564
Joined: Fri Jan 13, 2012 1:47 am
Contact:

variable declarations and scope

Post by monte » Mon Dec 02, 2013 11:02 pm

I'm wondering if the new parser might be able to handle variable declarations better than the current one. There's two things that I find annoying:
- declaring the same variable name in separate code blocks throws a shadowing error. While I don't really think we need block level variable scope I think it would be good if the parser were able to deal with this more gracefully otherwise it's impossible to declare variables close to their use in context where the same variable name is appropriate (a long switch where only a couple of blocks need the variable for example)

Code: Select all

if <something> then
   local tVar
   put SomeFunction() into tVar
   ...
else
   local tVar -- the engine can just ignore because the declaration is in a different block
   put SomeOtherFunction() into tVar
   ---
end if

-- tVar is not used out here so there's no real shadowing
- if a variable declaration has an assignment and it's in a loop to my mind it would make more sense if the engine re-assigned the value each iteration

Code: Select all

repeat
   local tIndex = 1 -- should reset tIndex to 1 each iteration
   repeat
      add 1 to tIndex
   end repeat
end repeat
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

dhurtt
Posts: 42
Joined: Sat Nov 09, 2013 7:37 pm
Location: Huachuca City, AZ

Re: variable declarations and scope

Post by dhurtt » Tue Dec 03, 2013 1:41 am

monte wrote:if a variable declaration has an assignment and it's in a loop to my mind it would make more sense if the engine re-assigned the value each iteration

Code: Select all

repeat
   local tIndex = 1 -- should reset tIndex to 1 each iteration
   repeat
      add 1 to tIndex
   end repeat
end repeat
Wow! I did not realize that it didn't.

Locked

Return to “Engine Contributors”