On 9 Jun., 23:31, Aaron Meurer <asmeu...@gmail.com> wrote:
> Yeah, surely there was a typo when you typed this.  The expression as
> given is not syntactically correct Python (you can't assign to x|y).
> Or else I (and I think everyone else too) is misunderstanding what you
> meant to say.

Sorry for the confusion, it was not meant to be Python. It would
translate to this code:

    a = x | y
    assert a == x if x else y

Or longer:

    if x:
        a = x
    else:
        a = y

> > I'm not sure what you're suggesting here. This looks like a programming
> > construct, which already exists in Python: 'x or y'. If it's meant to
> > return a symbolic expression, I'd say too much is implicit here and we
> > should rather use something like If(Ne(x, 0), x, y).

In Python this does not work with 'or', because 'or' always returns
either True or False, just like 'in'. (I would prefer to use 'or'
rather than '|'.) If you allowed 'or' to return an object, all boolean
logic would still work, and you could do some fancy expressive stuff.
Taken from a recent Go review [1]:

"""
Many people shun it, but the ?: ternary operator is a good idea, if
used correctly. Python does foo if bar else baz, which is a little
more verbose but still okay. Most dynamic languages, however, rock
with their boolean operators AND and OR not just evaluating to true
and false, but to the actual value that was considered true. Imagine
the assignment value = cmdline_option || "default". That requires a
decent boolean interpretation of all data types, however.
"""

Well, whether this is a good idea is arguable. Ronan, you will
probably think it is a bad idea, I guess. :)

> And like "and" and "or", I don't think you can override the
> triconditional.  "A if B else C" just evaluates bool(B) and returns A
> if it is True and C if it is False.

This is exactly what I wanted to happen.

Vinzent


[1] http://www.syntax-k.de/projekte/go-review

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to sympy@googlegroups.com.
To unsubscribe from this group, send email to 
sympy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to