• Subject: Re: goto in expressions
• From: Sean Conner <sean@...>
• Date: Tue, 16 Dec 2014 14:57:29 -0500

```It was thus said that the Great Andrew Starks once stated:
> [I searched for prior thread, which I remember existing, but I could
> not find it.]
>
> When I'm in a loop that uses continue, there is often a simple
> condition that I'm checking for, which will determine if I should skip
> or not.
>
> Here is a fake example:
> ```
> --if x is nil use y. If x os false or y is false-y, continue
> x = x == nil and y
>     or not x and  goto continue
>     or x
> ```
>
> I imagine that this does not work for good reason. However, I've had
> multiple occasions where I would have preferred this style over:
>
> ```
> local x = x == nil and y or x
>
> if not x then
>     goto continue
> end
> ```
>
> Even to me, the second style is a bit clearer, but a comment can make
> the first one clear and it has the benefit of dealing with this
> initialization in one go.

First off, you can do:

local x = x or y
if not x then
goto continue
end

(in other words:  "or" will do the "== nil" for you).  Now, you would like
to do:

local x = x or y or goto continue

I don't know of any language that has GOTO as an expression, as the
semantics of an "expression GOTO" don't make any sense.  I mean, what is the
meaning of:

local x = goto continue --?

"Well," you'll potentially say, "have 'goto ...' return nil."  Okay, but
then you get silly constructs like:

local x = goto continue or "Hello"

local x = 5 + goto continue

local x = some_table[some_key] = goto continue

Even if you exclude the above, having 'goto ... ' as an expression still
doesn't work because you can't have a bare expression in Lua:

3
unexpected symbol near '3'

You would be forced to do the silly

local x = goto continue

or you complicate the Lua parser to make 'goto ... ' into a statement OR an
expression, but only an expression in certain contexts because other
contexts don't make sense.

> While I would prefer that goto could be used in expressions, history
> has taught me that I'm about to have my mind changed. If someone could
> do me the favor of providing me with that narrative, I'd be most
> appreciative. :)

-spc (Is my narrative good enough?)

```