osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

What about idea of making a "Pythonic Lisp"...i.e. a Lisp that more closely resembles the syntax of Python?


On Fri, Sep 20, 2019 at 5:16 AM Cecil Westerhof <Cecil at decebal.nl> wrote:
>
> Paul Rubin <no.email at nospam.invalid> writes:
>
> >     Python 3.7.3 (default, Apr  3 2019, 05:39:12)
> >     Type "help", "copyright", "credits" or "license" for more information.
> >     >>> a = range(10)
> >     >>> b = reversed(a)
> >     >>> sum(a) == sum(b)
> >     True
> >     >>> sum(b) == sum(a)
> >     False
>
> Why does this happen?
>
> By the way, when you change the last statement to:
>     sum(a) == sum(b)
>
> you also get False.

>>> sum(range(10)) == sum(reversed(range(10)))
True

If you actually want a reversed range, use slice notation instead of
the reversed() function, which is more parallel to iter().

>>> a = range(10)
>>> b = a[::-1]
>>> sum(a) == sum(b)
True
>>> sum(b) == sum(a)
True

Now you actually have a range that runs the other direction, instead
of an iterator that runs through the range backwards.

ChrisA