I proposed this once upon a time: https://github.com/JuliaLang/julia/issues/1657; it wasn't popular. Please don't start commenting on that long-dead issue – keep the discussion here instead.
On Fri, May 6, 2016 at 4:08 PM, Tom Short <[email protected]> wrote: > You can make a quick macro for one-line if statements: > > macro when(condition, expr) > esc(:( if $condition; $expr; end)) > end > > @when 4 > pi x = 2 > > For even more compact syntax, you can replace `when` with `?`. > > > > > On Fri, May 6, 2016 at 3:12 PM, Adrian Salceanu <[email protected] > > wrote: > >> The only place where I find the "end" requirement annoying is for one >> line IF statements. When you have a short one liner, the "end" part just >> does not feel right. It would be nice if the "end" could be left out for >> one liners. Even PHP allows one to skip the accolades in such cases. >> >> If there's some other way of achieving this I'd love to hear about it. I >> don't like the ternary operator in this situation cause it forces me to add >> the 3rd part as "nothing" or whatever. And doing "expr1 && expr2" only >> works when expr2 is "return" for instance, otherwise the compiler complains >> about using a non-boolean in a boolean context. >> >> >> vineri, 6 mai 2016, 20:37:49 UTC+2, Stefan Karpinski a scris: >>> >>> There is a long history of languages using this syntax, including Algol, >>> Pascal, Ruby and Matlab. >>> >>> On Fri, May 6, 2016 at 2:26 PM, Ford Ox <[email protected]> wrote: >>> >>>> Is there any reasoning behind it? It seems to me like a weird choice >>>> since you have to type three letters, which is the complete opposite of the >>>> goal of this language - being very productive (a lot work done with little >>>> code). >>>> On top of that, brain has to read the word every time your eyes look at >>>> it so you spend more time also reading the code - tho this should be easy >>>> to omit, by highlighting this keyword by other color than other keywords >>>> (the current purple color in ATOM just drives me crazy, since it is one of >>>> the most violent colors, so my eyes always try to read that useless piece >>>> of information first, instead of the important code). >>>> >>> >>> >
