Re: problems with the scoping in eu4
- Posted by jeremy (admin) Jan 07, 2011
- 2108 views
Concerning variables declaration I repeat my suggestion to comeback to version 3.x situation.
The actual situation create inconsistancies and confusion without bringing any benefit.
I'm lost in this thread, what exactly are you speaking of that was added that does not provide any benefit? Are you speaking of:
sequence names = { "John Doe", "Jim Doe", "Jack Doe", "Joe Doe" } for i = 1 to length(names) do sequence name = names[i] sequence firstName = get_first_name(name) sequence lastName = get_last_name(name) if equal(lastName, "Doe") then printf(1, "CAUTION: Last name is really not known\n") end if printf(1, "Dear Mr. %s,\n\nThank you for your suggestion %s!", { lastName, firstName }) end for
i.e. declaring variables inside of a loop and those variables not persisting? If so (I think that is what we are talking about), that feature brings huge benefit into clean function design. I really hated not being able to do it 3.1. Being able to is a big step ahead for Euphoria. It would be a terrible thing if this functionality were to be reverted.
If you want a variable to persist, then you declare it in the scope it should persist in. For example:
sequence names = { "John Doe", "Jim Doe", "Jack Doe", "Joe Doe" } sequence lastNameProcessed = "None" for i = 1 to length(names) do sequence name = names[i] sequence firstName = get_first_name(name) sequence lastName = get_last_name(name) if equal(lastName, "Doe") then printf(1, "CAUTION: Last name is really not known\n") end if printf(1, "Dear Mr. %s,\n\nThank you for your suggestion %s!", { lastName, firstName }) lastNameProcessed = named end for printf(1, "Sent %d messages, last name processed was %s\n", { length(names), lastNameProcessed })
This is clean design and I'd suggest that everyone begin programming by keeping the variable to the minimum scope necessary.
Jeremy