shortened if
1
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)
?
2
Name:
Suddenly, Bananas
2013-02-10 14:27
Forgot a code tag....
3
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
4
Name:
Anonymous
2013-02-10 14:29
(case test
((a b c d)
(display "Haxus mein anuum.")
(newline)))
5
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.
6
Name:
Anonymous
2013-02-10 14:33
>>5
No, because that would be fucking retarded and illogical.
7
Name:
Anonymous
2013-02-10 14:36
>>6
Get out of my /frague/, cretinous fagshitoid.
8
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))
9
Name:
Anonymous
2013-02-10 14:37
CRETINANUS
10
Name:
Anonymous
2013-02-10 14:40
JEWS
11
Name:
Anonymous
2013-02-10 14:54
(define (faggot-predicate c . l)
(foldl (λ (v i) (or i (= v c))) #f l))
12
Name:
Anonymous
2013-02-10 15:31
>>8
Not in any language that will ever exist.
>>11
Where's your short circuiting?
13
Name:
Anonymous
2013-02-10 17:52
[a, b, c, d].indexOf(test) >= 0
14
Name:
Anonymous
2013-02-10 18:02
(cond) is as close as it gets
15
Name:
Anonymous
2013-02-10 18:13
if(test == (c = (a || b || c || d)))
I think that should work in C?
16
Name:
Anonymous
2013-02-10 18:17
[code] if test in [a, b, c, d]:
print 'FIOC wins again'
17
Name:
Anonymous
2013-02-10 18:18
>>16
if test in [a, b, c, d]:
print 'ONE WORD FORCED INDENTATION OF THE CODE /CODE'
18
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!
19
Name:
Anonymous
2013-02-10 18:38
>>18
Instantiate an array just to test a few values. Wonderful!
The optimizer takes care of that.
20
Name:
Anonymous
2013-02-10 18:52
21
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
22
Name:
Anonymous
2013-02-10 19:05
23
Name:
Anonymous
2013-02-10 19:08
Uh Earth to Troll, like, python's compiler is non-optimizing, ideeot.
24
Name:
Anonymous
2013-02-10 19:19
25
Name:
Anonymous
2013-02-10 20:07
>>24
Unrolling a constant array lookup is hardly 'optimising'
26
Name:
Anonymous
2013-02-10 20:12
>>25
The point was to prove
>>18 wrong.
27
Name:
Anonymous
2013-02-10 20:33
>>26
Well then well done for mutating the point beyond recognition.
28
Name:
Anonymous
2013-02-10 20:34
>>26
Also I bet the point still stands for Javashit.
29
Name:
Anonymous
2013-02-10 20:52
Newer Posts