Bug: pre-processor not respecting for loop scope.

This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location where you will have to reset your password.
Forum rules
This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location (https://forum.dynare.org) where you will have to reset your password.

Bug: pre-processor not respecting for loop scope.

Postby cfp » Thu May 20, 2010 1:57 pm

This is not a critical bug, but fixing it would help prevent people (e.g. me) shooting themselves in the foot.

If you have a pre-processor loop, for example:

Code: Select all
@#for lead in 1:offset
      LEAD@{lead}_FrakturIPart(0) = LEAD@{lead-1}_FrakturIPart(+1);
@#endfor


Then upon hitting the
Code: Select all
@#endfor
statement, the pre-processor variable
Code: Select all
lead
should ceased to be defined.

When copying and pasting code around it's very easy to accidentally end up with loop local variables that shouldn't be there. Throwing an error in this circumstance would be a great help.

Tom
cfp
 
Posts: 60
Joined: Mon Mar 15, 2010 9:18 pm

Re: Bug: pre-processor not respecting for loop scope.

Postby SébastienVillemot » Mon May 24, 2010 9:17 am

Hi,

This is not really a bug but a characteristic of the macro-language. This behavior is normal because all the macro-variables have global scope. There is no concept of local scope in the macro-language. Maybe we should make that more explicit in the documentation. And changing this behavior wouldn’t be easy. for implementation and backward compatibility reasons.

Best,
Sébastien Villemot
Economist at OFCE – Sciences Po
SébastienVillemot
 
Posts: 706
Joined: Fri Dec 07, 2007 2:29 pm
Location: Paris, France


Return to Dynare help

Who is online

Users browsing this forum: No registered users and 7 guests