#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Posts
    9
    Rep Power
    0

    I need "nor", "nand" expression


    Is there a way to get a nor (not or) expressoin that works in eval()?

    I would like eval() to handle for example this string "1 nor 0".
  2. #2
  3. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    13
    Boolean ...
    not (1 or 0)
    not (1 and 0)
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Posts
    9
    Rep Power
    0
    Thanks, but is it possible to make my own "nor" without to much work. That works in eval()? And that is used like "1 nor 0"?
  6. #4
  7. Commie Mutant Traitor
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Jun 2004
    Location
    Norcross, GA (again)
    Posts
    1,805
    Rep Power
    1570
    Originally Posted by southstar
    Thanks, but is it possible to make my own "nor" without to much work. That works in eval()? And that is used like "1 nor 0"?
    No; Python does not allow you to define new operators. While you can define a function nor(), it would have the same syntax and semantics as a normal function.

    Code:
    def nor(p, q):
        return not (p or q);
    Note that since Python (like most languages) evaluates function arguments eagerly, the clauses would be evaluated before the values are passed to the function, which means that any side-effects that the second clause would have would be take place regardless of the success or failure of the first clause.

    This can be seen as an argument in favor of adding a macro sublanguage to Python, I suppose, though one that would allow operators would probably be more complex than it would be worth.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Posts
    9
    Rep Power
    0
    Ok, thanks.

IMN logo majestic logo threadwatch logo seochat tools logo