[Python-ideas] where statement in Pyret

Ron Adam ron3200 at gmail.com
Sun Nov 10 19:37:24 CET 2013



On 11/10/2013 08:48 AM, Nick Coghlan wrote:
> On 10 November 2013 19:55, Tarek Ziadé<tarek at ziade.org>  wrote:
>> > From the documentation example:
>> >
>> >fun sum(l):
>> >   cases(List) l:
>> >     | empty => 0
>> >     | link(first, rest) => first + sum(rest)
>> >   end
>> >where:
>> >   sum([]) is 0
>> >   sum([1, 2, 3]) is 6
>> >end
> It would make more sense to just bake py.test style rich assertions
> into the language in some way and let people write:
>
>      def sum(iterable):
>          # implementation of sum
>
>      assert sum([]) == 0
>      assert sum([1, 2, 3]) == 6

> A mechanism to say "always execute assert statements in this module
> regardless of optimisation level" could also be useful.

+ 1

Currently assert statements are removed if the -O flag is used, but somehow 
that never seemed quite right to me.  It makes more sense to have a -A 
option to turn them on, rather than using -O to turn them off.

That change *along with* a way to "always execute asserts in this scope" 
would make asserts more useful.

Cheers,
    Ron



More information about the Python-ideas mailing list