Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Ternary Operator

Name: Anonymous 2010-01-08 8:07

ALL HAIL!

Name: Anonymous 2010-04-21 8:59

>>78
Invalid!

Name: Anonymous 2010-04-21 9:02

>>72,75
false_expr would also be evaluated if true_expr evaluated as false. But it works for stuff like print (debug && "Couldn't desecrate the mangina on line 45!" || "Something bad happened.")

Name: Anonymous 2010-04-21 9:19

>>82
Perl has a lovely way of solving that. You could also just use nesting.

As much as duplication of facilities is a tiresome path (see Perl), I really think S-expressions should show up in languages that don't strictly need them. The convenience of the ternary op could be unified with regular if/else blocks if done in S-expression form.

Name: Anonymous 2010-04-21 14:46

>>83
(See Perl && Perl or Perl)

Name: Anonymous 2010-04-23 19:07

w32BumpThread(wThisThread, W_TOP|W_SYNCHRONOUS, NULL, NULL, NULL)

Name: Anonymous 2010-04-24 5:43

s/\)/,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL\)/

Name: Anonymous 2010-07-09 6:01

I wanted to do something like foo = 4 (bar ? + : -) 2; and it doesn't work. Is there any clever way of making it work without putting the whole addition and subtraction inside the operator?

Name: Anonymous 2010-07-09 6:40

>>87
no

Name: Anonymous 2010-07-09 6:47

>>87
No, learn what expressions are

Name: Anonymous 2010-07-09 6:58

>>87
This isn't Haskell.

Name: Anonymous 2010-07-09 7:05

foo=4+bar?2:-2;

Name: Anonymous 2010-07-09 7:07

>>87
foo = 4 + (bar ? 2 : -2);
Or perhaps (faggot mode)
foo = 2 + (!bar) << 2;

Name: Anonymous 2010-07-09 7:09

            Func<int, int, int> add = (x, y) => x + y;
            Func<int, int, int> substract = (x, y) => x - y;
            var bar = true;
            var foo = (bar ? add : substract).Invoke(4, 2);

Name: Anonymous 2010-07-09 7:31

>>92
foo = 2 + (!bar) << 2;
I like it how you posted a solution that applies only to the particular case of addition/subtraction even though they were an obvious example.

Name: Anonymous 2010-07-09 7:54

>>94
Whatever you meant when you said that, it's easy to simplify whatever similar mathematical expression into that form.

Name: Anonymous 2010-07-09 11:46

opium dreams

Name: Anonymous 2010-07-09 11:51

people who `optimize" their programs into a nests of ternary expressions, don't know 'bout CPU Branch Predictors and penalty for not guessing the correct jump.
In fact most optimized program is one with least branches(jumps).

Name: Anonymous 2010-07-09 14:16

>>97
Solution: use conditionals that reduce to branchless arithmetic.

Name: Anonymous 2010-07-09 14:19

>>98
How do you mean?

Name: Anonymous 2010-07-09 14:21

>>98
Excuse me sir but, what the fuck are you talking about?

Name: Anonymous 2010-07-09 14:21

>>99
goto

Name: Anonymous 2010-07-09 14:36

>>99-101
Here's an example from recent nonsense:
http://dis.4chan.org/read/prog/1203076617

What's the first thing that comes to mind when you see that giant switch?

goto
Technically it fits the description, but no. Just no.

Name: Anonymous 2010-07-09 15:16

>>97
Or maybe our branch predictors don't suck.

Name: Anonymous 2010-07-10 0:09

>>103
There's no such thing as branch prediction that doesn't suck.

Name: Anonymous 2011-02-03 0:09


Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List