question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Extend assignment function notation

See original GitHub issue

I 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:open
  • Created 7 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
evhubcommented, Oct 7, 2016

@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.

0reactions
akdor1154commented, Jan 7, 2022

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 if def 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found