These are chat archives for evhub/coconut
Once again sorry if this is a naive question or if I've missed something in the documentation (some of which is still over my head at this point). Is it possible to do a 'conditional assignment' with Coconut? I've also been playing about with Elm and found it very useful in that language. For example I can do something like this:
case value: match 1: (a, b, c) = (1, 2, 3) match 2: (a, b, c) = (3, 2, 1) match _: (a, b, c) = (0, 0, 0)
but I'd like to reduce it to something more like this:
(a, b, c) = case value: match 1: (1, 2, 3) match 2: (3, 2, 1) match _: (0, 0, 0)
...which generates a CoconutParseError. Is there a nice way do do this in Coconut without having to type
(a, b, c) = in every branch of a
if .. elif .. else statement? Not so bad when there are only three branches and three values to assign, but on a larger scale it's a different matter. Thanks.
I've just seen #190 and the conversation about it earlier here. So I guess that answers my question for the time being. I really like the suggestion that
case statements (maybe even
if statements too) could be expressions. Maybe this could be distinguished syntactically from the normal uses of such statements by enclosing the conditional block inside some sort of opening and closing delimiters, such as parentheses or some variation i.e.
(if ...) or
(case ...) or something like that. So my previous example might look like:
(a, b, c) = ( case value: match 1: (1, 2, 3) match 2: (3, 2, 1) match _: (0, 0, 0) )
for example. (There may be reasons I don't know about why this is a terrible/impractical/impossible suggestion as I'm really not that proficient with Python/Coconut yet).