Was there more recent discussion about switch? I think I missed it, last
thing I am aware of is #5410. And of course see Switch.jl.
In any case, I find the proposed syntax a bit obscure and
complicated. I would prefer using the result of
findfirst(x->input % x == 0,[2,3,5,7])
or if that does not help, then explicit currying,
input = 119
let d(x) = input % x == 0
if d(2)
# code
elseif d(3)
# code
elseif d(5)
# code
elseif d(7)
# code
end
end
Best,
Tamas
On Mon, May 09 2016, Ford Ox wrote:
> I have a little suggestion: If julia is going to have switch, could we make
> it a bit better?
>
> Basically the switch would take two parameters : function and variable. On
> each case it would would
> call the function with those two params, and if the functions would return
> true, it would evaluate the case
> block.
>
> Note: the function has to return boolean.
>
> Example
>
> function divides(a, b)
> return a % b == 0
> end
>
> input = 119
> switch(divides, input)
> case 2 # this can be translated as ~ if(divides(input, 2))
> case 3 # 3 divides input without remainder
> case 5 # 5 divides input without remainder
> case 7 # 7 divides input without remainder
> end
>
> Of course you could achieve the default switch behavior like this:
> switch(==, input)
> ...
>
> What do you think about it?