Lichen

Changeset

528:ca18c51ae153
2017-02-02 Paul Boddie raw files shortlog changelog graph Rearranged iteration-related functionality within a __builtins__ subpackage.
lib/__builtins__/__init__.py (file) lib/__builtins__/dict.py (file) lib/__builtins__/iterable.py lib/__builtins__/iteration/__init__.py (file) lib/__builtins__/iteration/core.py (file) lib/__builtins__/iteration/enumeration.py (file) lib/__builtins__/iteration/functional.py (file) lib/__builtins__/iteration/iterator.py (file) lib/__builtins__/iteration/ordering.py (file) lib/__builtins__/iteration/quantifiers.py (file) lib/__builtins__/iteration/summary.py (file) lib/__builtins__/iterator.py lib/__builtins__/list.py (file) lib/__builtins__/set.py (file) lib/__builtins__/tuple.py (file)
     1.1 --- a/lib/__builtins__/__init__.py	Wed Feb 01 17:42:42 2017 +0100
     1.2 +++ b/lib/__builtins__/__init__.py	Thu Feb 02 22:38:26 2017 +0100
     1.3 @@ -62,7 +62,6 @@
     1.4  from __builtins__.float import float
     1.5  from __builtins__.int import int
     1.6  from __builtins__.span import range, slice, xrange
     1.7 -from __builtins__.iterator import itemiterator
     1.8  from __builtins__.list import list
     1.9  from __builtins__.long import long
    1.10  from __builtins__.none import None, NoneType
    1.11 @@ -79,7 +78,7 @@
    1.12  from __builtins__.comparable import cmp, hash
    1.13  from __builtins__.identity import callable, id, isinstance, issubclass, repr
    1.14  from __builtins__.io import open, raw_input, print_
    1.15 -from __builtins__.iterable import all, any, enumerate, filter, iter, len, map, max, min, reduce, reversed, sorted, sum, zip
    1.16 +from __builtins__.iteration import all, any, enumerate, filter, iter, len, map, max, min, reduce, reversed, sorted, sum, zip
    1.17  from __builtins__.namespace import dir, globals, locals, vars
    1.18  from __builtins__.numeric import abs, divmod, pow, round
    1.19  
     2.1 --- a/lib/__builtins__/dict.py	Wed Feb 01 17:42:42 2017 +0100
     2.2 +++ b/lib/__builtins__/dict.py	Thu Feb 02 22:38:26 2017 +0100
     2.3 @@ -19,7 +19,7 @@
     2.4  this program.  If not, see <http://www.gnu.org/licenses/>.
     2.5  """
     2.6  
     2.7 -from __builtins__.iterator import itemiterator
     2.8 +from __builtins__.iteration.iterator import itemiterator
     2.9  from __builtins__.span import _max
    2.10  from native import isinstance as _isinstance
    2.11  
     3.1 --- a/lib/__builtins__/iterable.py	Wed Feb 01 17:42:42 2017 +0100
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,189 +0,0 @@
     3.4 -#!/usr/bin/env python
     3.5 -
     3.6 -"""
     3.7 -Iteration-related functions.
     3.8 -
     3.9 -Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk>
    3.10 -
    3.11 -This program is free software; you can redistribute it and/or modify it under
    3.12 -the terms of the GNU General Public License as published by the Free Software
    3.13 -Foundation; either version 3 of the License, or (at your option) any later
    3.14 -version.
    3.15 -
    3.16 -This program is distributed in the hope that it will be useful, but WITHOUT
    3.17 -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    3.18 -FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    3.19 -details.
    3.20 -
    3.21 -You should have received a copy of the GNU General Public License along with
    3.22 -this program.  If not, see <http://www.gnu.org/licenses/>.
    3.23 -"""
    3.24 -
    3.25 -def all(iterable):
    3.26 -
    3.27 -    "Return whether all of the elements provided by 'iterable' are true."
    3.28 -
    3.29 -    for i in iterable:
    3.30 -        if not i:
    3.31 -            return False
    3.32 -
    3.33 -    return True
    3.34 -
    3.35 -def any(iterable):
    3.36 -
    3.37 -    "Return whether any of the elements provided by 'iterable' are true."
    3.38 -
    3.39 -    for i in iterable:
    3.40 -        if i:
    3.41 -            return True
    3.42 -
    3.43 -    return False
    3.44 -
    3.45 -def enumerate(iterable, start=0):
    3.46 -
    3.47 -    """
    3.48 -    Iterate over 'iterable', obtaining items and combining them with position
    3.49 -    information, producing a sequence containing tuples of the form
    3.50 -    (position, item). The first position is indicated by 'start' (which is zero
    3.51 -    by default) and each subsequent positions is incremented from the one
    3.52 -    preceding it.
    3.53 -    """
    3.54 -
    3.55 -    l = []
    3.56 -    pos = start
    3.57 -
    3.58 -    for i in iterable:
    3.59 -        l.append((pos, i))
    3.60 -        pos += 1
    3.61 -
    3.62 -    return l
    3.63 -
    3.64 -def filter(function, sequence):
    3.65 -
    3.66 -    """
    3.67 -    Apply 'function' to each element in 'sequence', returning a sequence of all
    3.68 -    elements for which the result of the function evaluated to a true value.
    3.69 -    """
    3.70 -
    3.71 -    l = []
    3.72 -    for i in sequence:
    3.73 -        if function(i):
    3.74 -            l.append(i)
    3.75 -    return l
    3.76 -
    3.77 -def iter(collection):
    3.78 -
    3.79 -    "Implementation of iter without callable plus sentinel support."
    3.80 -
    3.81 -    return collection.__iter__()
    3.82 -
    3.83 -def len(obj):
    3.84 -
    3.85 -    "Implementation of len."
    3.86 -
    3.87 -    return obj.__len__()
    3.88 -
    3.89 -def map(function, sequence):
    3.90 -
    3.91 -    """
    3.92 -    Apply 'function' to each element of 'sequence' in turn, appending the result
    3.93 -    to a new sequence containing all results.
    3.94 -    """
    3.95 -
    3.96 -    l = []
    3.97 -    for i in sequence:
    3.98 -        l.append(function(i))
    3.99 -    return l
   3.100 -
   3.101 -def max(args):
   3.102 -
   3.103 -    "Implementation of max."
   3.104 -
   3.105 -    highest = None
   3.106 -    for arg in args:
   3.107 -        if highest is None or arg > highest:
   3.108 -            highest = arg
   3.109 -    return highest
   3.110 -
   3.111 -def min(args):
   3.112 -
   3.113 -    "Implementation of min."
   3.114 -
   3.115 -    lowest = None
   3.116 -    for arg in args:
   3.117 -        if lowest is None or arg < lowest:
   3.118 -            lowest = arg
   3.119 -    return lowest
   3.120 -
   3.121 -_reduce_default = object()
   3.122 -
   3.123 -def reduce(function, sequence, initial=_reduce_default):
   3.124 -
   3.125 -    """
   3.126 -    Using 'function', reduce the given 'sequence' to a single result.
   3.127 -
   3.128 -    With no 'initial' value specified, the first two elements in the 'sequence'
   3.129 -    are used with the function to produce an initial result. With an initial
   3.130 -    result available, a subsequent result is computed by using the initial
   3.131 -    result and the next element in the sequence with the function.
   3.132 -
   3.133 -    All subsequent results are computed using the current result and the next
   3.134 -    available element with the function. This continues for all remaining
   3.135 -    elements until the end of the sequence is reached.
   3.136 -    """
   3.137 -
   3.138 -    result = initial
   3.139 -
   3.140 -    for i in sequence:
   3.141 -        if result is _reduce_default:
   3.142 -            result = i
   3.143 -        else:
   3.144 -            result = function(result, i)
   3.145 -
   3.146 -    return result
   3.147 -
   3.148 -def reversed(sequence):
   3.149 -
   3.150 -    "Return a reversed version of the given 'sequence'."
   3.151 -
   3.152 -    return sequence[::-1]
   3.153 -
   3.154 -def sorted(iterable, cmp=None, key=None, reverse=False): pass
   3.155 -
   3.156 -def sum(sequence, start=0):
   3.157 -
   3.158 -    "Sum the elements in 'sequence', adding to any indicated 'start' value."
   3.159 -
   3.160 -    total = start
   3.161 -    for i in sequence:
   3.162 -        total += i
   3.163 -    return total
   3.164 -
   3.165 -def zip(args):
   3.166 -
   3.167 -    """
   3.168 -    Zip the given 'args' together, producing for each index position tuples
   3.169 -    containing the values for that position from each of the 'args'.
   3.170 -    """
   3.171 -
   3.172 -    result = []
   3.173 -    pos = 0
   3.174 -
   3.175 -    # Repeat until one of the arguments runs out of elements.
   3.176 -
   3.177 -    while True:
   3.178 -        l = []
   3.179 -
   3.180 -        # Visit each argument in turn, collecting elements in the given
   3.181 -        # position.
   3.182 -
   3.183 -        for arg in args:
   3.184 -            try:
   3.185 -                l.append(arg[pos])
   3.186 -            except IndexError:
   3.187 -                return result
   3.188 -
   3.189 -        result.append(tuple(l))
   3.190 -        pos += 1
   3.191 -
   3.192 -# vim: tabstop=4 expandtab shiftwidth=4
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/lib/__builtins__/iteration/__init__.py	Thu Feb 02 22:38:26 2017 +0100
     4.3 @@ -0,0 +1,29 @@
     4.4 +#!/usr/bin/env python
     4.5 +
     4.6 +"""
     4.7 +Iteration-related functionality.
     4.8 +
     4.9 +Copyright (C) 2017 Paul Boddie <paul@boddie.org.uk>
    4.10 +
    4.11 +This program is free software; you can redistribute it and/or modify it under
    4.12 +the terms of the GNU General Public License as published by the Free Software
    4.13 +Foundation; either version 3 of the License, or (at your option) any later
    4.14 +version.
    4.15 +
    4.16 +This program is distributed in the hope that it will be useful, but WITHOUT
    4.17 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    4.18 +FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    4.19 +details.
    4.20 +
    4.21 +You should have received a copy of the GNU General Public License along with
    4.22 +this program.  If not, see <http://www.gnu.org/licenses/>.
    4.23 +"""
    4.24 +
    4.25 +from __builtins__.iteration.enumeration import enumerate
    4.26 +from __builtins__.iteration.core import iter, len
    4.27 +from __builtins__.iteration.functional import filter, map, reduce, zip
    4.28 +from __builtins__.iteration.quantifiers import all, any
    4.29 +from __builtins__.iteration.ordering import reversed, sorted
    4.30 +from __builtins__.iteration.summary import max, min, sum
    4.31 +
    4.32 +# vim: tabstop=4 expandtab shiftwidth=4
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/lib/__builtins__/iteration/core.py	Thu Feb 02 22:38:26 2017 +0100
     5.3 @@ -0,0 +1,34 @@
     5.4 +#!/usr/bin/env python
     5.5 +
     5.6 +"""
     5.7 +Core iteration-related functions.
     5.8 +
     5.9 +Copyright (C) 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
    5.10 +
    5.11 +This program is free software; you can redistribute it and/or modify it under
    5.12 +the terms of the GNU General Public License as published by the Free Software
    5.13 +Foundation; either version 3 of the License, or (at your option) any later
    5.14 +version.
    5.15 +
    5.16 +This program is distributed in the hope that it will be useful, but WITHOUT
    5.17 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    5.18 +FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    5.19 +details.
    5.20 +
    5.21 +You should have received a copy of the GNU General Public License along with
    5.22 +this program.  If not, see <http://www.gnu.org/licenses/>.
    5.23 +"""
    5.24 +
    5.25 +def iter(collection):
    5.26 +
    5.27 +    "Implementation of iter without callable plus sentinel support."
    5.28 +
    5.29 +    return collection.__iter__()
    5.30 +
    5.31 +def len(obj):
    5.32 +
    5.33 +    "Implementation of len."
    5.34 +
    5.35 +    return obj.__len__()
    5.36 +
    5.37 +# vim: tabstop=4 expandtab shiftwidth=4
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/lib/__builtins__/iteration/enumeration.py	Thu Feb 02 22:38:26 2017 +0100
     6.3 @@ -0,0 +1,41 @@
     6.4 +#!/usr/bin/env python
     6.5 +
     6.6 +"""
     6.7 +Enumeration-related functions.
     6.8 +
     6.9 +Copyright (C) 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
    6.10 +
    6.11 +This program is free software; you can redistribute it and/or modify it under
    6.12 +the terms of the GNU General Public License as published by the Free Software
    6.13 +Foundation; either version 3 of the License, or (at your option) any later
    6.14 +version.
    6.15 +
    6.16 +This program is distributed in the hope that it will be useful, but WITHOUT
    6.17 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    6.18 +FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    6.19 +details.
    6.20 +
    6.21 +You should have received a copy of the GNU General Public License along with
    6.22 +this program.  If not, see <http://www.gnu.org/licenses/>.
    6.23 +"""
    6.24 +
    6.25 +def enumerate(iterable, start=0):
    6.26 +
    6.27 +    """
    6.28 +    Iterate over 'iterable', obtaining items and combining them with position
    6.29 +    information, producing a sequence containing tuples of the form
    6.30 +    (position, item). The first position is indicated by 'start' (which is zero
    6.31 +    by default) and each subsequent positions is incremented from the one
    6.32 +    preceding it.
    6.33 +    """
    6.34 +
    6.35 +    l = []
    6.36 +    pos = start
    6.37 +
    6.38 +    for i in iterable:
    6.39 +        l.append((pos, i))
    6.40 +        pos += 1
    6.41 +
    6.42 +    return l
    6.43 +
    6.44 +# vim: tabstop=4 expandtab shiftwidth=4
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/lib/__builtins__/iteration/functional.py	Thu Feb 02 22:38:26 2017 +0100
     7.3 @@ -0,0 +1,101 @@
     7.4 +#!/usr/bin/env python
     7.5 +
     7.6 +"""
     7.7 +Functional operations for iterators.
     7.8 +
     7.9 +Copyright (C) 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
    7.10 +
    7.11 +This program is free software; you can redistribute it and/or modify it under
    7.12 +the terms of the GNU General Public License as published by the Free Software
    7.13 +Foundation; either version 3 of the License, or (at your option) any later
    7.14 +version.
    7.15 +
    7.16 +This program is distributed in the hope that it will be useful, but WITHOUT
    7.17 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    7.18 +FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    7.19 +details.
    7.20 +
    7.21 +You should have received a copy of the GNU General Public License along with
    7.22 +this program.  If not, see <http://www.gnu.org/licenses/>.
    7.23 +"""
    7.24 +
    7.25 +def filter(function, sequence):
    7.26 +
    7.27 +    """
    7.28 +    Apply 'function' to each element in 'sequence', returning a sequence of all
    7.29 +    elements for which the result of the function evaluated to a true value.
    7.30 +    """
    7.31 +
    7.32 +    l = []
    7.33 +    for i in sequence:
    7.34 +        if function(i):
    7.35 +            l.append(i)
    7.36 +    return l
    7.37 +
    7.38 +def map(function, sequence):
    7.39 +
    7.40 +    """
    7.41 +    Apply 'function' to each element of 'sequence' in turn, appending the result
    7.42 +    to a new sequence containing all results.
    7.43 +    """
    7.44 +
    7.45 +    l = []
    7.46 +    for i in sequence:
    7.47 +        l.append(function(i))
    7.48 +    return l
    7.49 +
    7.50 +_reduce_default = object()
    7.51 +
    7.52 +def reduce(function, sequence, initial=_reduce_default):
    7.53 +
    7.54 +    """
    7.55 +    Using 'function', reduce the given 'sequence' to a single result.
    7.56 +
    7.57 +    With no 'initial' value specified, the first two elements in the 'sequence'
    7.58 +    are used with the function to produce an initial result. With an initial
    7.59 +    result available, a subsequent result is computed by using the initial
    7.60 +    result and the next element in the sequence with the function.
    7.61 +
    7.62 +    All subsequent results are computed using the current result and the next
    7.63 +    available element with the function. This continues for all remaining
    7.64 +    elements until the end of the sequence is reached.
    7.65 +    """
    7.66 +
    7.67 +    result = initial
    7.68 +
    7.69 +    for i in sequence:
    7.70 +        if result is _reduce_default:
    7.71 +            result = i
    7.72 +        else:
    7.73 +            result = function(result, i)
    7.74 +
    7.75 +    return result
    7.76 +
    7.77 +def zip(args):
    7.78 +
    7.79 +    """
    7.80 +    Zip the given 'args' together, producing for each index position tuples
    7.81 +    containing the values for that position from each of the 'args'.
    7.82 +    """
    7.83 +
    7.84 +    result = []
    7.85 +    pos = 0
    7.86 +
    7.87 +    # Repeat until one of the arguments runs out of elements.
    7.88 +
    7.89 +    while True:
    7.90 +        l = []
    7.91 +
    7.92 +        # Visit each argument in turn, collecting elements in the given
    7.93 +        # position.
    7.94 +
    7.95 +        for arg in args:
    7.96 +            try:
    7.97 +                l.append(arg[pos])
    7.98 +            except IndexError:
    7.99 +                return result
   7.100 +
   7.101 +        result.append(tuple(l))
   7.102 +        pos += 1
   7.103 +
   7.104 +# vim: tabstop=4 expandtab shiftwidth=4
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/lib/__builtins__/iteration/iterator.py	Thu Feb 02 22:38:26 2017 +0100
     8.3 @@ -0,0 +1,44 @@
     8.4 +#!/usr/bin/env python
     8.5 +
     8.6 +"""
     8.7 +Iterator objects.
     8.8 +
     8.9 +Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk>
    8.10 +
    8.11 +This program is free software; you can redistribute it and/or modify it under
    8.12 +the terms of the GNU General Public License as published by the Free Software
    8.13 +Foundation; either version 3 of the License, or (at your option) any later
    8.14 +version.
    8.15 +
    8.16 +This program is distributed in the hope that it will be useful, but WITHOUT
    8.17 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    8.18 +FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    8.19 +details.
    8.20 +
    8.21 +You should have received a copy of the GNU General Public License along with
    8.22 +this program.  If not, see <http://www.gnu.org/licenses/>.
    8.23 +"""
    8.24 +
    8.25 +class itemiterator:
    8.26 +
    8.27 +    "An iterator for objects providing item access."
    8.28 +
    8.29 +    def __init__(self, l):
    8.30 +
    8.31 +        "Initialise with the given list 'l'."
    8.32 +
    8.33 +        self.l = l
    8.34 +        self.i = 0
    8.35 +
    8.36 +    def next(self):
    8.37 +
    8.38 +        "Return the next item."
    8.39 +
    8.40 +        try:
    8.41 +            value = self.l[self.i]
    8.42 +            self.i += 1
    8.43 +            return value
    8.44 +        except IndexError:
    8.45 +            raise StopIteration()
    8.46 +
    8.47 +# vim: tabstop=4 expandtab shiftwidth=4
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/lib/__builtins__/iteration/ordering.py	Thu Feb 02 22:38:26 2017 +0100
     9.3 @@ -0,0 +1,34 @@
     9.4 +#!/usr/bin/env python
     9.5 +
     9.6 +"""
     9.7 +Ordering-related functions.
     9.8 +
     9.9 +Copyright (C) 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
    9.10 +
    9.11 +This program is free software; you can redistribute it and/or modify it under
    9.12 +the terms of the GNU General Public License as published by the Free Software
    9.13 +Foundation; either version 3 of the License, or (at your option) any later
    9.14 +version.
    9.15 +
    9.16 +This program is distributed in the hope that it will be useful, but WITHOUT
    9.17 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    9.18 +FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    9.19 +details.
    9.20 +
    9.21 +You should have received a copy of the GNU General Public License along with
    9.22 +this program.  If not, see <http://www.gnu.org/licenses/>.
    9.23 +"""
    9.24 +
    9.25 +def reversed(sequence):
    9.26 +
    9.27 +    "Return a reversed version of the given 'sequence'."
    9.28 +
    9.29 +    return sequence[::-1]
    9.30 +
    9.31 +def sorted(iterable, cmp=None, key=None, reverse=False):
    9.32 +
    9.33 +    # NOTE: To be implemented.
    9.34 +
    9.35 +    pass
    9.36 +
    9.37 +# vim: tabstop=4 expandtab shiftwidth=4
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/lib/__builtins__/iteration/quantifiers.py	Thu Feb 02 22:38:26 2017 +0100
    10.3 @@ -0,0 +1,42 @@
    10.4 +#!/usr/bin/env python
    10.5 +
    10.6 +"""
    10.7 +Quantifier functions.
    10.8 +
    10.9 +Copyright (C) 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
   10.10 +
   10.11 +This program is free software; you can redistribute it and/or modify it under
   10.12 +the terms of the GNU General Public License as published by the Free Software
   10.13 +Foundation; either version 3 of the License, or (at your option) any later
   10.14 +version.
   10.15 +
   10.16 +This program is distributed in the hope that it will be useful, but WITHOUT
   10.17 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
   10.18 +FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
   10.19 +details.
   10.20 +
   10.21 +You should have received a copy of the GNU General Public License along with
   10.22 +this program.  If not, see <http://www.gnu.org/licenses/>.
   10.23 +"""
   10.24 +
   10.25 +def all(iterable):
   10.26 +
   10.27 +    "Return whether all of the elements provided by 'iterable' are true."
   10.28 +
   10.29 +    for i in iterable:
   10.30 +        if not i:
   10.31 +            return False
   10.32 +
   10.33 +    return True
   10.34 +
   10.35 +def any(iterable):
   10.36 +
   10.37 +    "Return whether any of the elements provided by 'iterable' are true."
   10.38 +
   10.39 +    for i in iterable:
   10.40 +        if i:
   10.41 +            return True
   10.42 +
   10.43 +    return False
   10.44 +
   10.45 +# vim: tabstop=4 expandtab shiftwidth=4
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/lib/__builtins__/iteration/summary.py	Thu Feb 02 22:38:26 2017 +0100
    11.3 @@ -0,0 +1,51 @@
    11.4 +#!/usr/bin/env python
    11.5 +
    11.6 +"""
    11.7 +Iterator summary functions.
    11.8 +
    11.9 +Copyright (C) 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
   11.10 +
   11.11 +This program is free software; you can redistribute it and/or modify it under
   11.12 +the terms of the GNU General Public License as published by the Free Software
   11.13 +Foundation; either version 3 of the License, or (at your option) any later
   11.14 +version.
   11.15 +
   11.16 +This program is distributed in the hope that it will be useful, but WITHOUT
   11.17 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
   11.18 +FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
   11.19 +details.
   11.20 +
   11.21 +You should have received a copy of the GNU General Public License along with
   11.22 +this program.  If not, see <http://www.gnu.org/licenses/>.
   11.23 +"""
   11.24 +
   11.25 +def max(args):
   11.26 +
   11.27 +    "Implementation of max."
   11.28 +
   11.29 +    highest = None
   11.30 +    for arg in args:
   11.31 +        if highest is None or arg > highest:
   11.32 +            highest = arg
   11.33 +    return highest
   11.34 +
   11.35 +def min(args):
   11.36 +
   11.37 +    "Implementation of min."
   11.38 +
   11.39 +    lowest = None
   11.40 +    for arg in args:
   11.41 +        if lowest is None or arg < lowest:
   11.42 +            lowest = arg
   11.43 +    return lowest
   11.44 +
   11.45 +def sum(sequence, start=0):
   11.46 +
   11.47 +    "Sum the elements in 'sequence', adding to any indicated 'start' value."
   11.48 +
   11.49 +    total = start
   11.50 +    for i in sequence:
   11.51 +        total += i
   11.52 +    return total
   11.53 +
   11.54 +# vim: tabstop=4 expandtab shiftwidth=4
    12.1 --- a/lib/__builtins__/iterator.py	Wed Feb 01 17:42:42 2017 +0100
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,44 +0,0 @@
    12.4 -#!/usr/bin/env python
    12.5 -
    12.6 -"""
    12.7 -Iterator objects.
    12.8 -
    12.9 -Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk>
   12.10 -
   12.11 -This program is free software; you can redistribute it and/or modify it under
   12.12 -the terms of the GNU General Public License as published by the Free Software
   12.13 -Foundation; either version 3 of the License, or (at your option) any later
   12.14 -version.
   12.15 -
   12.16 -This program is distributed in the hope that it will be useful, but WITHOUT
   12.17 -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
   12.18 -FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
   12.19 -details.
   12.20 -
   12.21 -You should have received a copy of the GNU General Public License along with
   12.22 -this program.  If not, see <http://www.gnu.org/licenses/>.
   12.23 -"""
   12.24 -
   12.25 -class itemiterator:
   12.26 -
   12.27 -    "An iterator for objects providing item access."
   12.28 -
   12.29 -    def __init__(self, l):
   12.30 -
   12.31 -        "Initialise with the given list 'l'."
   12.32 -
   12.33 -        self.l = l
   12.34 -        self.i = 0
   12.35 -
   12.36 -    def next(self):
   12.37 -
   12.38 -        "Return the next item."
   12.39 -
   12.40 -        try:
   12.41 -            value = self.l[self.i]
   12.42 -            self.i += 1
   12.43 -            return value
   12.44 -        except IndexError:
   12.45 -            raise StopIteration()
   12.46 -
   12.47 -# vim: tabstop=4 expandtab shiftwidth=4
    13.1 --- a/lib/__builtins__/list.py	Wed Feb 01 17:42:42 2017 +0100
    13.2 +++ b/lib/__builtins__/list.py	Thu Feb 02 22:38:26 2017 +0100
    13.3 @@ -19,7 +19,7 @@
    13.4  this program.  If not, see <http://www.gnu.org/licenses/>.
    13.5  """
    13.6  
    13.7 -from __builtins__.iterator import itemiterator
    13.8 +from __builtins__.iteration.iterator import itemiterator
    13.9  from __builtins__.sequence import sequence
   13.10  from native import list_append, list_concat, list_element, list_init, \
   13.11                     list_len, list_nonempty, list_setelement, list_setsize
    14.1 --- a/lib/__builtins__/set.py	Wed Feb 01 17:42:42 2017 +0100
    14.2 +++ b/lib/__builtins__/set.py	Thu Feb 02 22:38:26 2017 +0100
    14.3 @@ -3,7 +3,7 @@
    14.4  """
    14.5  Set objects.
    14.6  
    14.7 -Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk>
    14.8 +Copyright (C) 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
    14.9  
   14.10  This program is free software; you can redistribute it and/or modify it under
   14.11  the terms of the GNU General Public License as published by the Free Software
   14.12 @@ -19,6 +19,8 @@
   14.13  this program.  If not, see <http://www.gnu.org/licenses/>.
   14.14  """
   14.15  
   14.16 +from __builtins__.iteration.iterator import itemiterator
   14.17 +
   14.18  class frozenset:
   14.19      def __init__(self, iterable): pass
   14.20  
    15.1 --- a/lib/__builtins__/tuple.py	Wed Feb 01 17:42:42 2017 +0100
    15.2 +++ b/lib/__builtins__/tuple.py	Thu Feb 02 22:38:26 2017 +0100
    15.3 @@ -19,7 +19,7 @@
    15.4  this program.  If not, see <http://www.gnu.org/licenses/>.
    15.5  """
    15.6  
    15.7 -from __builtins__.iterator import itemiterator
    15.8 +from __builtins__.iteration.iterator import itemiterator
    15.9  from __builtins__.sequence import hashable, sequence
   15.10  from native import list_element, list_init, list_len, list_setsize, \
   15.11                     list_setelement