# Copyright (C) 2022, H. Conrad Cunningham
# Exploring Languages with Interpreters and Functional Programming

# Modified modular programming example from Ch. 2
# Arithmetic Sequence Module

#234567890123456789012345678901234567890123456789012345678901234567890

# 2022-03-08: Developed from 2018-07-04 modular example
# 2022-03-10: Renamed incr() as adv(), set_defaults() as reset()
#             Renamed variables start and stop
# 2022-03-14: Renamed variables with underscores to make private

_start  =  0
_stop   = 10
_change =  1
_count  = _start

# Add a reset mutator. Should it be 3 or 4?
def reset(new_start, new_stop, new_change):
    global _start, _stop, _change, _count
    _start = new_start
    _stop  = new_stop
    _count = _start
    if new_change == 0:
        print('Error: Attempt to reset increment to 0; not reset.')
        print(f'Call: reset({new_start=}, {new_stop=}, {new_change=})')
        print(f'State: {_start=}; {_stop=}; {_change=}; {_count=};')
    else:
        _change = new_change

def adv():
    global _count 
    _count = _count + _change

def get_count():
    return _count

def has_more():
    if _change > 0:
        return _count <= _stop
    else:
        return _count >= _stop

    
# Smoke testing
if __name__ == '__main__':
    print('Arithmetic sequence module')
    print(f'{_start=}; {_stop=}; {_change=}; {_count=};')

    
    

