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

Pages: 1-

What should.... ?

Name: Anonymous 2011-09-29 14:54

What should

a ? b = c : b = d

do?

Name: Anonymous 2011-09-29 14:59

I'd rather do

b = a ? c : d;

Name: Anonymous 2011-09-29 15:04

(set! b (if a c d))

Name: Anonymous 2011-09-29 15:09

right way

if(a != 0){
  b = c;
}else{ //a==0
  b = d;
}

Name: Anonymous 2011-09-29 15:11

>>4
Disgusting, even Enterprise Java has ternary.

Name: Anonymous 2011-09-29 15:17

>>1
If you're talking about C, the ternary ?: operator has lower precedence than assignment, so both of the assignments will be executed (in undefined order).  Then a will be evaluated and the expression will return the value of b = c if a is non-zero or b = d otherwise.  The assignment operator returns what was assigned, so the result of the expression will be either c or d.

Name: Anonymous 2011-09-29 15:22

>>4
( ≖‿≖)

Name: Anonymous 2011-09-29 15:26

b = c*a + d*a;

Name: Anonymous 2011-09-29 15:27

>>8
wrong if a is not 0 or 1

Name: Anonymous 2011-09-29 15:30

>>8

( ≖‿≖) ( ≖‿≖) ( ≖‿≖)

Name: Anonymous 2011-09-29 15:35

b = (c*a) + (-d*(a-1))

Name: Anonymous 2011-09-29 15:40

>>8 is wrong because:
Considering a is either 1 or 0
If a = 1
b = (c*1) + (d*1) then b = c + d

>>11, on the other way, is better
*** If a = 1 ***

b = (c*1) + (-d*0)

then b = c

*** If a = 0 ***

b = (c*0) + (-d*(0-1))
b = (0) + (-d*-1))
b = (-d*-1)


then b = d

Name: Anonymous 2011-09-29 16:03

ternery oparetor

Name: Anonymous 2011-09-29 16:13

ternery oparetor

Name: Anonymous 2011-09-29 17:12

>>6
oh god its like a train wrekc.  please to be trolling.

Name: Anonymous 2011-09-29 17:55

>>15
9 posts before someone caught this.  I think that there are not programmers on /prog/.

Name: Anonymous 2011-09-29 18:14

ternery oparetor

Name: Anonymous 2011-09-30 1:08

oh god oh god i missed /prog/ so much.....

Name: Anonymous 2011-09-30 2:18

>>16
I do not bother with operator precedence, because in sane programming languages, they are usually just right(tm). Sane, i.e. not C/C++.

Name: Anonymous 2011-09-30 7:07

>>12
what if a is either 0 or not 0?

Name: Anonymous 2011-09-30 7:18

>>20  
b = ( c* (a/a) ) + (- d *( (a/a) - 1 ))

Name: Anonymous 2011-09-30 7:21


input b>acd output >x000
if a!=0 x=c
else x=d

[[-]>>[-]<<]>>[<[-]>[-<<<+>>>]]

Name: Anonymous 2011-09-30 7:22

>>22
forgot to return pointer to x add <<< to end

Name: Anonymous 2011-09-30 7:47

>>21
that would work... only if 0/0=0

Name: Anonymous 2011-09-30 8:56

Give a syntax error. =c is not a complete, valid, command nor an operand.

Name: Anonymous 2011-09-30 9:47

My LoseThos compiler makes code that executes both clauses of a ? operator, all the time.  That's not good.  I would have to duplicate a lot of code from "if" statements.  I kinda don't want to junk-up my compiler (more).  I don't have a strong hatred of "?" operators, like some people, but I don't use them.  I'm hardly a prude when it comes to making indecipherable C expressions in other ways.

Name: Anonymous 2011-09-30 16:18

>>26
So your C+ is actually more of a C-.

Name: Anonymous 2011-10-01 11:07

is_lisp ? shit : !shit;

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