-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Switch lambdas #4
Comments
"Following is the expression returning the value to be evaluated if the switch matches" -- does that mean one can assign a value to the switch? I hope not. If not, here is a better wording: "Following is the expression to be evaluated if the switch matches." |
I'd also like a Ruby-style match foo {
case /1$/: print "Foo ends with a one"
case =>(foo) foo % 4: print "Foo is not divisible by 4"
//maybe this as well when lazy ranges (a bit like generators) are implemented
case 'foo'...'bar.': print "Foo is greater than 'foo' but less than 'bar.'"
} |
@somebody1234 hm okay. I can understand lambdas but with regexes, how will it know if the two items are equal? |
@vihanb what do you mean by "equal"? |
Regexes.... |
If you implement it using regexes for non primitives you lose the speed up offered by switch statements on close ranges of integers. |
@vihanb Ruby makes it match when it's a string and the regex matches IIRC |
@somebody1234 right, but what I meant was. what function will it check to see if it matches a |
|
Idea: |
@ConorOBrien-Foxx Literal matching? like regex/lambda matching? |
Yay, tag action galore 😑 |
The syntax is kind of vague as of now. When does the switch end? When the next condition begins?
|
This proposal details the workings of the planned
switch
(optionally*
) statement.Overview
The switch lambda is a block statement which functions both as a literal and a conditional block. In it's literal form it owns its own class rather than a TC link.
Definition
The syntax is either
switch
orswitch *
whereswitch *
specifies a switch literal. There may be any amount of whitespace betweenswitch
and*
, if*
exists. Following is the expression to be evaluated if the switch matches. This is followed by a block surrounded with braces{}
of newline-seperated statements, which are the conditionals. Conditionals either begin withcase
orelse
, ifcase
, then the beginning description is optional. Following is an expression which returns the value to be matched against, commands in these expressions serve as a logical OR during matching. These are followed by a:
representing a single statement may follow. Or curly braces{}
which allows for a multi-line code blockFormal Grammar
EBNF
The text was updated successfully, but these errors were encountered: