Extend assignment function notation
See original GitHub issueI think it would be useful if “match” and “case” statements were actually expressions. For example, I’d like to be able to do things like:
def whats_this(foo) =
case foo:
match 0:
#<do something>
"Zero"
match 1:
#<do something else>
"One"
else:
"Dunno"
assert "Zero" == whats_this(0)
assert "One" == whats_this(1)
assert "Dunno" == whats_this(2)
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Function Notation - Extension + Practice - Teacher Desmos
Assign. Create an account or sign in to assign this activity to your classes. ... 1Writing Function Notation - From a point on...
Read more >Function Notation - MathMaine
Function Notation in Math Class the notation provides names for us to use when referring to them. We can then use “f” and...
Read more >2.1: Functions and Function Notation - Mathematics LibreTexts
Identify functions given an equation or a graph. Function notation explained. Evaluate fucntions from a formula or a graph.
Read more >11.1 Function Notation – Intermediate Algebra
The logic of excluded values is the extension of a property from arithmetic: ... One of the features of function notation is the...
Read more >Function Notation Worksheet Teaching Resources | TPT
3.2 Day 2 Function Notation & Evaluation Assignment ... including a student worksheet and suggested support and extension activities.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@Nexus6 Yeah, I totally agree that this would be useful–it’s something I’ve been wanting to implement since I resolved #159. Putting this issue on the v1.2.1 milestone.
Its not so much about filling use case checkboxes, it’s more (again, just from user perspective here) about consistency.
There are already special cases that work towards this: your alternative ternary operator (not needed if
if
is an expression), statement lambdas (would be sometimes not needed ifdef fn
is an expression), probably more…With everything-is-expression, the above special cases mostly become unnecessary, and the requests for other special cases (why not a match expr to go with ternary expr? Why does a statement lambda on my last line return a func, but a def func return None?) go away.
As before, the languages Coconut is inspired by largely work this way already - as a user I find the python ‘actually this thing is a statement and will silently eval to None’ paradigm to be jarring in Coconut’s otherwise functional environments.
In practice with these other languages I haven’t noticed an issue with clarity around what a deeply nested expression returns - as long as there is clear syntax to delineate the expression as a unit, which Py/Coconut’s whitespace does beautifully.