Re: [go-nuts] if/switch statements as expressions

2019-01-13 Thread Sokolov Yura
Ruby has `if`, `switch` and `while` expressions. next = if cur.val < val cur.right else cur.left end Union type is not necessary, because there could be restriction forcing all branches to have same type. -- You received this message because

Re: [go-nuts] if/switch statements as expressions

2018-12-22 Thread 'Axel Wagner' via golang-nuts
On Sat, Dec 22, 2018 at 8:05 PM Viktor Kojouharov wrote: > Curiously, Java 12 will also support switch expressions, and java is about > as non-expressive as it gets. > What makes you say that? Java is as much of an expression language as C. In particular, assignments are expressions, which I thi

Re: [go-nuts] if/switch statements as expressions

2018-12-22 Thread Sameer Ajmani
Inline functions can meet this need, though there's usually a better way: v := func() T { if b { return v1 } return v2 }() On Sat, Dec 22, 2018 at 2:05 PM Viktor Kojouharov wrote: > I've used kotlin extensively, where ifs and switches are expressions. I've > also seen rust support them. Curiously

Re: [go-nuts] if/switch statements as expressions

2018-12-22 Thread Viktor Kojouharov
I've used kotlin extensively, where ifs and switches are expressions. I've also seen rust support them. Curiously, Java 12 will also support switch expressions, and java is about as non-expressive as it gets. On Wednesday, December 19, 2018 at 11:39:32 PM UTC+2, Tyler Compton wrote: > > There is

Re: [go-nuts] if/switch statements as expressions

2018-12-21 Thread Jamie Clarkson
It seems to me that what he was railing against was the design-by-committee approach? Having never studied Algol68 it's hard to say but skimming the wiki page parts of it could be transposed directly into one about Go so I'm not sure the DNA is totally gone, just we're lucky to avoid the commit

Re: [go-nuts] if/switch statements as expressions

2018-12-21 Thread Michael Jones
It is always good to be reading Dijkstra. He was a treasure. His observations were those of the computing world, and combined with IBM’s dominance and desire behind PL/1, created the dead zone from which C saved us all. Unfortunately the good of these dead ends was lost, and the good of Algol68 wa

Re: [go-nuts] if/switch statements as expressions

2018-12-21 Thread Jamie Clarkson
Happened to be randomly rereading through the EWD archives and came upon this simultaneously with reading this thread: http://www.cs.utexas.edu/users/EWD/transcriptions/EWD02xx/EWD230.html (no comment!) Jamie On Friday, December 21, 2018 at 7:57:07 AM UTC, Tom Mitchell wrote: > > > On Thu, Dec

Re: [go-nuts] if/switch statements as expressions

2018-12-20 Thread Tom Mitchell
On Thu, Dec 20, 2018 at 2:48 PM Michael Jones wrote: > interesting! i wish algol 68 had had its chance. > Well, "It ain't over till it is over." http://algol68.sourceforge.net/ " multiple licenses that should be read carefully: it is open source software, but not all components are fully f

Re: [go-nuts] if/switch statements as expressions

2018-12-20 Thread Michael Jones
interesting! i wish algol 68 had had its chance. On Thu, Dec 20, 2018 at 2:40 PM Bakul Shah wrote: > On Thu, 20 Dec 2018 13:13:04 -0800 Michael Jones > wrote: > > > > There is an inelegant but highly effective "hack" in GCC/G++ in thuas > area. > > Since C/C++ are expression language as Rob put

Re: [go-nuts] if/switch statements as expressions

2018-12-20 Thread Bakul Shah
On Thu, 20 Dec 2018 13:13:04 -0800 Michael Jones wrote: > > There is an inelegant but highly effective "hack" in GCC/G++ in thuas area. > Since C/C++ are expression language as Rob put it (e.g. a statement like > "3" compiles where in Go it fails with "3 evaluated but not used") GCC took > this a

Re: [go-nuts] if/switch statements as expressions

2018-12-20 Thread Michael Jones
There is an inelegant but highly effective "hack" in GCC/G++ in thuas area. Since C/C++ are expression language as Rob put it (e.g. a statement like "3" compiles where in Go it fails with "3 evaluated but not used") GCC took this a step further and implemented that the last expression evaluated in

Re: [go-nuts] if/switch statements as expressions

2018-12-19 Thread Jan Mercl
On Wed, Dec 19, 2018 at 9:16 PM Jan Mercl <0xj...@gmail.com> wrote: >> On Wed, Dec 19, 2018 at 9:09 PM Viktor Kojouharov wrote: >> >> I'm interested to know whether it was considered (I can't imagine that it wasn't) for if and switch statements to be expressions instead > > I can't imagine it was

Re: [go-nuts] if/switch statements as expressions

2018-12-19 Thread Rob Pike
BCPL had a construct like this, and we did consider doing something analogous, but in the end Go is not an expression language. C and BCPL are, and that property does lead to problems, although they are probably avoidable with careful language design. But Go is not an expression language, so contr

Re: [go-nuts] if/switch statements as expressions

2018-12-19 Thread Tyler Compton
There is some precedent. Python has an if expression of sorts that is distinct from its if statements: print(value1 if condition else value2) And in all Lisp dialects I'm familiar with, if is an expression: (print (if condition value1 value2)) Not to say that this means Go should support it nec

Re: [go-nuts] if/switch statements as expressions

2018-12-19 Thread Ian Lance Taylor
On Wed, Dec 19, 2018 at 12:09 PM Viktor Kojouharov wrote: > > I've tried and failed at finding any previous discussion on this topic, so do > point me to one if it exists. > > I'm interested to know whether it was considered (I can't imagine that it > wasn't) for if and switch statements to be e

Re: [go-nuts] if/switch statements as expressions

2018-12-19 Thread Jan Mercl
On Wed, Dec 19, 2018 at 9:09 PM Viktor Kojouharov wrote: > I'm interested to know whether it was considered (I can't imagine that it wasn't) for if and switch statements to be expressions instead I can't imagine it was considered. Is there a precedence in other language? Not even C supports tha

[go-nuts] if/switch statements as expressions

2018-12-19 Thread Viktor Kojouharov
Hello, I've tried and failed at finding any previous discussion on this topic, so do point me to one if it exists. I'm interested to know whether it was considered (I can't imagine that it wasn't) for if and switch statements to be expressions instead, and if so, why were they ultimately left