On Apr 17, 2009, at 11:00 AM, MikeF wrote: > Hi All, > > Newbie issue. > > I'm new to Sage but was messing about with Westers logical inference > problem ( x>=y, y>=z, z>=z) and then using == and = by itself in the > bool function. I've simplified the logic and isolated what I believe > to be an error in behavior, perhaps designed but ought to be warned > against. I found no warning. > > The function bool seems to always generate true when constructed as > "print bool( x= some variable)". Perhaps it is the global variable > usage. My work around is not to use the variable x within logical > constructs. It may or may not relate to the equivalence problem in > Wester. >
This is because the Python bool constructor names it's first argument "x" and so x is getting passed in as a keyword argument. In pure Python: >>> bool(x=5) True >>> bool(x=None) False Note that this is a common problem: >>> int(x=2) 2 I'm not sure there's anything we can do about this (short of raising a warning in the preparser, which IMHO is a bad idea). We could also write our own is_true function, which doesn't accept keyword arguments and passes on to bool. - Robert --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---