Note that the function that is called by "^" is __xor__.  So you can already
do a.__xor__(b).  If you want to write the function that David describes,
calling a.__xor__(b) is better than using eval.
David

On Mon, Mar 10, 2008 at 6:34 AM, David Joyner <[EMAIL PROTECTED]> wrote:

>
> Another solution (avoiding the preparer) is to simply define
>
> sage: def xor(a,b):  return eval("%s^%s"%(a,b))
> ....:
> sage: xor(1,0)
> 1
> sage: xor(1,1)
> 0
>
> which mimics the native Python behavior:
>
> Python 2.5.1 (r251:54863, Oct  5 2007, 13:50:07)
> [GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> 1^0
> 1
> >>> 1^1
> 0
>
>
> On Mon, Mar 10, 2008 at 5:30 AM, vgermrk <[EMAIL PROTECTED]> wrote:
> >
> >  Since the preparser replaces "^" with "**"  (which is good!),
> >  i want a way to access the python-buildin-XOR again.
> >
> >  I suggested in IRC that the preparser should also replace "xor" with
> >  "^",
> >  so that one can do   "5 xor 3".
> >  But since i did not convince everybody (on IRC), let's discuss here
> >  about it.
> >
> >  So what do you think?
> >
> >  -vgermrk-
> >  >
> >
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to