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

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

#234567890123456789012345678901234567890123456789012345678901234567890

# 2022-03-08: Developed from from Arithmetic Seqeunce Module
# 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  =   1
_stop   = 100
_change =   2
_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 abs(new_change) <= 1:
        print('Error: Attempt to set abs(_change) <= 1; 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():
    return abs(_count) <= abs(_stop)


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