Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limit to number of terms in an expression?

Edit: This is confirmed by apple as a compiler error.

The first if expression below (17 terms) compiles, and produces the expected result (false). The second if expression (18 terms) fails with the error message:

Cannot invoke '||' with an argument list of type '($T106,$T110)'.

The two expressions are identical except for the extra term.

I have no problem working around the problem, but I just don't understand what it is complaining about. Can someone enlighten me as to what stupid mistake I am making? Be gentle, very inexperienced coder here.

import Darwin

var a = -1
if
    a == 0 ||
        a == 1 ||
        a == 2 ||
        a == 3 ||
        a == 4 ||
        a == 5 ||
        a == 6 ||
        a == 7 ||
        a == 8 ||
        a == 9 ||
        a == 10 ||
        a == 11 ||
        a == 12 ||
        a == 13 ||
        a == 14 ||
        a == 15 ||
        a == 16 ||
        a == 17 { println("value was true") } else { println("value was false")}

if
    a == 0 ||
        a == 1 ||
        a == 2 ||
        a == 3 ||
        a == 4 ||
        a == 5 ||
        a == 6 ||
        a == 7 ||
        a == 8 ||
        a == 9 ||
        a == 10 ||
        a == 11 ||
        a == 12 ||
        a == 13 ||
        a == 14 ||
        a == 15 ||
        a == 16 ||
        a == 17 ||
        a == 18 { println("value was true") } else { println("value was false")}
like image 813
Henry Avatar asked Aug 20 '14 18:08

Henry


People also ask

What is the limit of an expression?

In mathematics, a limit is a value toward which an expression converges as one or more variables approach certain values. Limits are important in calculus and analysis. Consider the limit of the expression 2 x + 3 as x approaches 0.

What are the 3 rules of limits?

The limit of a product is equal to the product of the limits. The limit of a quotient is equal to the quotient of the limits. The limit of a constant function is equal to the constant. The limit of a linear function is equal to the number x is approaching.


1 Answers

While the bug is solved you can use this:

switch a {
case 0...17:
    println("value was true")
default:
    println("value was false")
}
like image 184
Alberto Barrera Avatar answered Nov 12 '22 10:11

Alberto Barrera