hylang/hy — pull request #637 by microamp (2014-08-22 10:24:16+00:00)
Title: Implement drop-last (and reimplement butlast)

This PR implements ``drop-last``.

I have also reimplemented ``butlast`` in terms of ``drop-last`` in order to make it work well with lazy/infinite sequences. The problem with the current implementation is that it would only work well with fully realised collections and iterators that implement ``__len__`` which can be problematic in some cases. Please consider the following examples.

```hy
=> (butlast (interleave (range 10) (range 10 20)))
```
```python
Traceback (most recent call last):
File "", line 1, in
File "/home/microamp/devel/projs/hy/hy/core/language.hy", line 41, in butlast
(itertools.islice coll 0 (dec (len coll))))
TypeError: object of type 'itertools.chain' has no len()
```

```hy
=> (import itertools)
=> (take 5 (butlast (itertools.count)))
```
```python
Traceback (most recent call last):
File "", line 1, in
File "/home/microamp/devel/projs/hy/hy/core/language.hy", line 41, in butlast
(itertools.islice coll 0 (dec (len coll))))
TypeError: object of type 'itertools.count' has no len()
```

Please find the new tests to see how ``drop-last``/``butlast`` handle lazy/infinite sequences now.

Thanks for reviewing in advance.