Skip to content
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

switch / if-elseif-elseif-else term #3199

Closed
danielmewes opened this issue Oct 17, 2014 · 18 comments
Closed

switch / if-elseif-elseif-else term #3199

danielmewes opened this issue Oct 17, 2014 · 18 comments
Assignees
Milestone

Comments

@danielmewes
Copy link
Member

Currently the r.branch() term isn't that great to use if you have more complex case distinctions.

Proposed by @wojons: Add a variadic term taking 2N+1 arguments

r.switch(cond1, val1, cond2, val2, ..., condN, valN, default_val)

Its semantics are those of the following code block in C:

if (cond1) return val1;
else if (cond2) return val2;
...
else if (condN) return valN;
else return default_val;

We could also make r.branch() variadic, instead of introducing a new term.

@wojons
Copy link
Contributor

wojons commented Oct 17, 2014

@danielmewes

Thank you, One thing i want to add. I think it would be important for that after the default value you can submit another aarray or object that allows u to control if its a if else or if its a switch. Or a r.break term will need to be added so it will stop letting things fall though.

@timmaxw
Copy link
Member

timmaxw commented Oct 17, 2014

I think that we should simply allow r.branch() to take 2N+1 arguments where N>=1. The current behavior of r.branch() is simply the N=1 case.

@wojons
Copy link
Contributor

wojons commented Oct 17, 2014

i think thise is ur guys call on how you want to do this.....

@gchpaco
Copy link
Contributor

gchpaco commented Oct 17, 2014

As far as bike shedding goes, multi-branch if statements mean "cond" to my brain. I could live with switch. Branch is a bit weird, but I could probably get used to it in time.

@timmaxw
Copy link
Member

timmaxw commented Oct 17, 2014

I don't really like the name r.branch either (I wanted to call it r.if_then_else) but given that we already have the command r.branch, I think we shouldn't introduce a new separate command.

@mlucy
Copy link
Member

mlucy commented Oct 17, 2014

Another vote for making branch more powerful rather than adding another term. We already have so many that it's hard to keep track of them all.

@danielmewes
Copy link
Member Author

Let's finalize this during the 1.17 ReQL discussion period, not now...

@wojons
Copy link
Contributor

wojons commented Oct 17, 2014

The only reason that i would recommend r.switch over r.branch is as a user first looking at rethinkdb and trying to find a way to do condations r.branch does not sound like its going to be for what i amlooking for i think it was @AtnNn that showed me that command. But as a devloper seeing a command called switch sounds like a switch statment.i would ad r.switch and deperatcate r.branch.

@danielmewes danielmewes modified the milestones: 2.1, subsequent Mar 5, 2015
@coffeemug
Copy link
Contributor

👍 for extending r.branch and not introducing a new term.

@deontologician
Copy link
Contributor

extending r.branch seems obviously good.

@wojons
Copy link
Contributor

wojons commented Apr 22, 2015

I think r.branch sounds more like its forking something but fair enough for extending it as long as i dont have to use 10 of them.

@VeXocide
Copy link
Member

Extending r.branch seems obvious, are we considering renaming it as well?

@danielmewes
Copy link
Member Author

I'd like to keep the renaming discussion separate and for later.

@danielmewes
Copy link
Member Author

Marking as settled for making branch variadic to support multiple branches.

@pilwon
Copy link

pilwon commented May 14, 2015

👍 fantastic idea to make r.branch more powerful!

@danielmewes danielmewes modified the milestones: 2.2-polish, 2.2 Aug 27, 2015
@encryptio encryptio self-assigned this Aug 31, 2015
encryptio added a commit that referenced this issue Sep 2, 2015
@encryptio
Copy link
Contributor

Done in next as of bf5b28b, CR 3201

@mlucy
Copy link
Member

mlucy commented Sep 2, 2015

@encryptio -- is there a docs issue?

@encryptio
Copy link
Contributor

@mlucy Writing an issue out now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants