These are chat archives for evhub/coconut

21st
Feb 2017
Evan Hubinger
@evhub
Feb 21 2017 00:23

@realms-of-chaos Interesting idea! With your simple example (not doing any complicated pattern-matching stuff in the match statements), you could do

a, b, c = (
    (1, 2, 3) if value == 1 else
    (3, 2, 1) if value == 2 else
    (0, 0, 0)
)

but that wouldn't work if you wanted to do more complex pattern-matching. Like you said, you could define a function, and do

def vals(1) = (1, 2, 3)

@addpattern(vals)
def vals(2) = (1, 2, 3)

@addpattern(vals)
def vals(_) = (0, 0, 0)

a, b, c = vals(value)

and that would always work, though I agree that it's a bit clunky.

Mark S I Taylor
@realms-of-chaos
Feb 21 2017 18:09
Hi, thanks for the first example using a conditional expression as I didn't realise that would work with more than one branch. That just wasn't clear from https://www.python.org/dev/peps/pep-0308/ , or how exactly the syntax would look if it was valid.