[plt-scheme] "Hiding" a global variable

From: Todd O'Bryan (toddobryan at gmail.com)
Date: Wed Oct 21 15:39:37 EDT 2009

Or at least realize that your professor is likely to read this list... :-)

On Wed, Oct 21, 2009 at 12:42 PM, Stephen Bloch <sbloch at adelphi.edu> wrote:
>
> On Oct 20, 2009, at 11:00 PM, Mike wrote:
>
>> I have a rather difficult homework question. I would like to know what
>> direction to look in in order to solve it:
>>
>> "Develop a function named next that takes no arguments, but each time
>> you call it, it returns how many times it has been called:
>>
>>> (next)
>>
>> 1
>>>
>>> (next)
>>
>> 2
>>>
>>> (next)
>>
>> 3
>>
>>
>> Hint: You can do this with a global variable, but it would be "neater"
>> if you could hide the variable. Think about local.... "
>
> Mike, one of your classmates was just in my office asking about the same
> problem.  Here's another hint.
>
> You need a local in order to have a variable that the function can update,
> but not have this variable be globally visible.  But if you put the local
> inside the function definition, it'll create a NEW variable every time you
> call the function, so that's no good.  Thus the local must be OUTSIDE the
> function definition.
>
> See if that gets you a little farther.
>
>
>
> Dr. Stephen Bloch
> Math/CS Department
> Adelphi University
> sbloch at adelphi.edu
>
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>


Posted on the users mailing list.