On Thu, 20 Dec 2018 13:13:04 -0800 Michael Jones <michael.jo...@gmail.com> 
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 step further and implemented that the last expression evaluated in a
> block is the value of that block. This makes "x = {if (a>b) then 7 else
> 2;}" do what "x = (a>b)?7:2" means but allows any and all code in there.
> Won't work in Go because of "3 evaluated but not used" but I've used it
> gratefully in macro situations in the past.

Algol-68 allowed this by design. No hack required! The value
of a sequence of expressions was the last expression. It also
allowed if and switch expressions. And it allowed much more
concise alternate syntax for some constructs but with exactly
the same semantics. Among other things this meant the language
had to have union types.
  x := IF cond THEN 1 ELSE "foo" FI
or
  x := (cond | 1 | "foo")
is a perfectly legal expression. So is this:
  CASE x IN
    (INT i): foo(i),
    (STRING s): bar(s),
    OUT error(x)
  ESAC

In my view Go could've been more of an expression language
without losing any of its strong points.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to