On 9/8/10 6:35 PM, mda_ wrote:
sage: is_triangular_number(0)
0
sage: is_triangular_number(1)
1
sage: is_triangular_number(2)
False
sage: is_triangular_number(3)
2
This is the same duck-typing style choice I made before. Example
where unexpected output is generated:
sage: [x for x in [0..3] if not is_triangular_number(x)]
[0, 2]
sage: [x for x in [0..3] if is_triangular_number(x)]
[1, 3]
The "not" coerces 0 into True, thereby keeping it in the list
comprehension. Should I file a bug?
is_* functions should always return True or False explicitly, in my
opinion, partly because of this reason.
In the existing implementation, you can just explicitly check for False:
sage: [x for x in [0..3] if is_triangular_number(x) is not False]
Thanks,
Jason
--
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org