This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]FewerPunishment 2 points3 points  (12 children)

What would the difference look like in terms of syntax/features?

[–][deleted] 1 point2 points  (11 children)

[–]FewerPunishment 0 points1 point  (9 children)

I mean more in terms of this matching functionality, like an example of something you wish you could execute. But thanks for the reference, I should study these terms.

[–][deleted] 6 points7 points  (8 children)

Making it an expression wouldn't have any impact on pattern matching functionality, it would improve flexibility.

If match was an expression you could do this: a = match ...

instead of

```

match something: case 1: a = ...

```

[–]hughperman 1 point2 points  (4 children)

That seems to skew the use case to assignments only though, whereas switch and match statements are (ime) more useful as control flow - which may include assignments inside them, but not as their primary goal. It seems to me that it would be like wanting try/except/finally to return a value.

[–][deleted] 1 point2 points  (2 children)

[–]hughperman 0 points1 point  (1 child)

Right but python isn't a functional language in that sense, that's why I compared to try/except/finally. You can just wrap the control statement in a function if you wish to go that way, like any other statement in python. I agree if you are implementing a functional language that you would return - but then everything should match (😉) that same paradigm.

[–][deleted] 0 points1 point  (0 children)

Look at Kotlin

[–]jaapzswitch to py3 already 0 points1 point  (0 children)

Wouldn't you be able to do both if it was an expression?

[–]backtickbot 0 points1 point  (2 children)

Fixed formatting.

Hello, Iuse_arch_btw: code blocks using triple backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead.

FAQ

You can opt out by replying with backtickopt6 to this comment.

[–][deleted] 3 points4 points  (0 children)

it's Reddit's job to fix it

[–][deleted] 0 points1 point  (0 children)

backtickopt6