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

shortened if

Name: Suddenly, Bananas 2013-02-10 14:26

Do any languages allow you to shorten an if statement like this:
if (test == a || test == b || test == c || test == d)
to something like this:
[code]if (test == a || b || c || d)
?

Name: Suddenly, Bananas 2013-02-10 14:27

Forgot a code tag....

Name: Anonymous 2013-02-10 14:29

The second if would be interpreted as:
if test is equal to a, or b is true, or c is true, or d is true

Name: Anonymous 2013-02-10 14:29

(case test
  ((a b c d)
    (display "Haxus mein anuum.")
    (newline)))

Name: Anonymous 2013-02-10 14:31

>>3
Yes fucking obviously, >>1 was asking whether there existed some syntax similar to that which matched the semantics of the first expression.

Name: Anonymous 2013-02-10 14:33

>>5
No, because that would be fucking retarded and illogical.

Name: Anonymous 2013-02-10 14:36

>>6
Get out of my /frague/, cretinous fagshitoid.

Name: Suddenly, Bananas 2013-02-10 14:37

So maybe it would make more sense using something like this:
if (test == (a || b || c || d))

Name: Anonymous 2013-02-10 14:37

CRETINANUS

Name: Anonymous 2013-02-10 14:40

JEWS

Name: Anonymous 2013-02-10 14:54

(define (faggot-predicate  c . l)
    (foldl (λ (v i) (or i (= v c))) #f l))

Name: Anonymous 2013-02-10 15:31

>>8
Not in any language that will ever exist.
>>11
Where's your short circuiting?

Name: Anonymous 2013-02-10 17:52

[a, b, c, d].indexOf(test) >= 0

Name: Anonymous 2013-02-10 18:02

(cond) is as close as it gets

Name: Anonymous 2013-02-10 18:13

if(test == (c = (a || b || c || d)))

I think that should work in C?

Name: Anonymous 2013-02-10 18:17

[code]if test in [a, b, c, d]:
    print 'FIOC wins again'

Name: Anonymous 2013-02-10 18:18

>>16
if test in [a, b, c, d]:
    print 'ONE WORD FORCED INDENTATION OF THE CODE /CODE'

Name: Anonymous 2013-02-10 18:29

>>15
Kill yourself or learn how the language features you're trying to use actually work

>>13,16,17
Instantiate an array just to test a few values. Wonderful!

Name: Anonymous 2013-02-10 18:38

>>18
Instantiate an array just to test a few values. Wonderful!
The optimizer takes care of that.

Name: Anonymous 2013-02-10 18:52

>>19
"The optimizer"?

Name: Anonymous 2013-02-10 19:03

>>20
Yeah, the Python compiler's optimizer.  It takes care of things like that.

>>> def f(x,a,b,c,d):
...  if x in [a,b,c,d]:
...   return 'FIOC'
...
>>> dis.dis(f)
  2           0 LOAD_FAST                0 (x)
              3 LOAD_FAST                1 (a)
              6 COMPARE_OP               2 (==)
              9 POP_JUMP_IF_TRUE        48
             12 LOAD_FAST                0 (x)
             15 LOAD_FAST                2 (b)
             18 COMPARE_OP               2 (==)
             21 POP_JUMP_IF_TRUE        48
             24 LOAD_FAST                0 (x)
             27 LOAD_FAST                3 (c)
             30 COMPARE_OP               2 (==)
             33 POP_JUMP_IF_TRUE        48
             36 LOAD_FAST                0 (x)
             39 LOAD_FAST                4 (d)
             42 COMPARE_OP               2 (==)
             45 POP_JUMP_IF_FALSE       52

  3     >>   48 LOAD_CONST               1 ('FIOC')
             51 RETURN_VALUE       
        >>   52 LOAD_CONST               0 (None)
             55 RETURN_VALUE

Name: Anonymous 2013-02-10 19:05

>>21
Python compiler
lel

Name: Anonymous 2013-02-10 19:08

Uh Earth to Troll, like, python's compiler is non-optimizing, ideeot.

Name: Anonymous 2013-02-10 19:19

>>23
then explain >>21

Name: Anonymous 2013-02-10 20:07

>>24
Unrolling a constant array lookup is hardly 'optimising'

Name: Anonymous 2013-02-10 20:12

>>25
The point was to prove >>18 wrong.

Name: Anonymous 2013-02-10 20:33

>>26
Well then well done for mutating the point beyond recognition.

Name: Anonymous 2013-02-10 20:34

>>26
Also I bet the point still stands for Javashit.

Name: Anonymous 2013-02-10 20:52

Perl 6's Junctions are exactly this.

http://en.wikibooks.org/wiki/Perl_6_Programming/Junctions

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