[Proposal] break do end

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

[Proposal] break do end

Soni "They/Them" L.
It would be cool if you could use break with do ... end for some sort of
"safe goto"

Example:

do
break
local x = "you'll never see me"
print(x)
end
print("something")

Would print "something"

In 5.2+ we have this:

goto x
local x = ""
::x::
print("something")

But it errors instead of doing the scoping stuff you can do with do ... end

(This is probably not something for lua 5 but for lua 6 if/when we get
it... it would probably be less harmful to change goto so that it does
an implicit do ... end scoping thingy)

Reply | Threaded
Open this post in threaded view
|

Re: [Proposal] break do end

Coda Highland
On Wed, Aug 27, 2014 at 7:17 PM, Thiago L. <[hidden email]> wrote:

> It would be cool if you could use break with do ... end for some sort of
> "safe goto"
>
> Example:
>
> do
> break
> local x = "you'll never see me"
> print(x)
> end
> print("something")
>
> Would print "something"
>
> In 5.2+ we have this:
>
> goto x
> local x = ""
> ::x::
> print("something")
>
> But it errors instead of doing the scoping stuff you can do with do ... end
>
> (This is probably not something for lua 5 but for lua 6 if/when we get it...
> it would probably be less harmful to change goto so that it does an implicit
> do ... end scoping thingy)
>

repeat
  -- statements here
  break
  -- rest of statements skipped
until false

/s/ Adam

Reply | Threaded
Open this post in threaded view
|

Re: [Proposal] break do end

Soni "They/Them" L.

On 27/08/14 11:34 PM, Coda Highland wrote:

> On Wed, Aug 27, 2014 at 7:17 PM, Thiago L. <[hidden email]> wrote:
>> It would be cool if you could use break with do ... end for some sort of
>> "safe goto"
>>
>> Example:
>>
>> do
>> break
>> local x = "you'll never see me"
>> print(x)
>> end
>> print("something")
>>
>> Would print "something"
>>
>> In 5.2+ we have this:
>>
>> goto x
>> local x = ""
>> ::x::
>> print("something")
>>
>> But it errors instead of doing the scoping stuff you can do with do ... end
>>
>> (This is probably not something for lua 5 but for lua 6 if/when we get it...
>> it would probably be less harmful to change goto so that it does an implicit
>> do ... end scoping thingy)
>>
> repeat
>    -- statements here
>    break
>    -- rest of statements skipped
> until false
>
> /s/ Adam
>
until true*, but that's uglier

Reply | Threaded
Open this post in threaded view
|

Re: [Proposal] break do end

Coda Highland
On Wed, Aug 27, 2014 at 7:35 PM, Thiago L. <[hidden email]> wrote:

>
> On 27/08/14 11:34 PM, Coda Highland wrote:
>>
>> On Wed, Aug 27, 2014 at 7:17 PM, Thiago L. <[hidden email]> wrote:
>>>
>>> It would be cool if you could use break with do ... end for some sort of
>>> "safe goto"
>>>
>>> Example:
>>>
>>> do
>>> break
>>> local x = "you'll never see me"
>>> print(x)
>>> end
>>> print("something")
>>>
>>> Would print "something"
>>>
>>> In 5.2+ we have this:
>>>
>>> goto x
>>> local x = ""
>>> ::x::
>>> print("something")
>>>
>>> But it errors instead of doing the scoping stuff you can do with do ...
>>> end
>>>
>>> (This is probably not something for lua 5 but for lua 6 if/when we get
>>> it...
>>> it would probably be less harmful to change goto so that it does an
>>> implicit
>>> do ... end scoping thingy)
>>>
>> repeat
>>    -- statements here
>>    break
>>    -- rest of statements skipped
>> until false
>>
>> /s/ Adam
>>
> until true*, but that's uglier
>

No, until true would make it loop. until false makes the body of the
loop execute exactly once.

/s/ Adam

Reply | Threaded
Open this post in threaded view
|

Re: [Proposal] break do end

Rena
On Wed, Aug 27, 2014 at 11:00 PM, Coda Highland <[hidden email]> wrote:

> On Wed, Aug 27, 2014 at 7:35 PM, Thiago L. <[hidden email]> wrote:
>>
>> On 27/08/14 11:34 PM, Coda Highland wrote:
>>>
>>> On Wed, Aug 27, 2014 at 7:17 PM, Thiago L. <[hidden email]> wrote:
>>>>
>>>> It would be cool if you could use break with do ... end for some sort of
>>>> "safe goto"
>>>>
>>>> Example:
>>>>
>>>> do
>>>> break
>>>> local x = "you'll never see me"
>>>> print(x)
>>>> end
>>>> print("something")
>>>>
>>>> Would print "something"
>>>>
>>>> In 5.2+ we have this:
>>>>
>>>> goto x
>>>> local x = ""
>>>> ::x::
>>>> print("something")
>>>>
>>>> But it errors instead of doing the scoping stuff you can do with do ...
>>>> end
>>>>
>>>> (This is probably not something for lua 5 but for lua 6 if/when we get
>>>> it...
>>>> it would probably be less harmful to change goto so that it does an
>>>> implicit
>>>> do ... end scoping thingy)
>>>>
>>> repeat
>>>    -- statements here
>>>    break
>>>    -- rest of statements skipped
>>> until false
>>>
>>> /s/ Adam
>>>
>> until true*, but that's uglier
>>
>
> No, until true would make it loop. until false makes the body of the
> loop execute exactly once.
>
> /s/ Adam
>

The logic is "until true == true", so it will only loop once. You're
thinking of "while true".

--
Sent from my Game Boy.

Reply | Threaded
Open this post in threaded view
|

Re: [Proposal] break do end

Coda Highland
On Wed, Aug 27, 2014 at 8:02 PM, Rena <[hidden email]> wrote:

> On Wed, Aug 27, 2014 at 11:00 PM, Coda Highland <[hidden email]> wrote:
>> On Wed, Aug 27, 2014 at 7:35 PM, Thiago L. <[hidden email]> wrote:
>>>
>>> On 27/08/14 11:34 PM, Coda Highland wrote:
>>>>
>>>> On Wed, Aug 27, 2014 at 7:17 PM, Thiago L. <[hidden email]> wrote:
>>>>>
>>>>> It would be cool if you could use break with do ... end for some sort of
>>>>> "safe goto"
>>>>>
>>>>> Example:
>>>>>
>>>>> do
>>>>> break
>>>>> local x = "you'll never see me"
>>>>> print(x)
>>>>> end
>>>>> print("something")
>>>>>
>>>>> Would print "something"
>>>>>
>>>>> In 5.2+ we have this:
>>>>>
>>>>> goto x
>>>>> local x = ""
>>>>> ::x::
>>>>> print("something")
>>>>>
>>>>> But it errors instead of doing the scoping stuff you can do with do ...
>>>>> end
>>>>>
>>>>> (This is probably not something for lua 5 but for lua 6 if/when we get
>>>>> it...
>>>>> it would probably be less harmful to change goto so that it does an
>>>>> implicit
>>>>> do ... end scoping thingy)
>>>>>
>>>> repeat
>>>>    -- statements here
>>>>    break
>>>>    -- rest of statements skipped
>>>> until false
>>>>
>>>> /s/ Adam
>>>>
>>> until true*, but that's uglier
>>>
>>
>> No, until true would make it loop. until false makes the body of the
>> loop execute exactly once.
>>
>> /s/ Adam
>>
>
> The logic is "until true == true", so it will only loop once. You're
> thinking of "while true".
>
> --
> Sent from my Game Boy.
>

Er. Right. Yes, I'm thinking of while. Sorry, I'm derping today. ^^()

/s/ Adam

Reply | Threaded
Open this post in threaded view
|

Re: [Proposal] break do end

Coroutines
In reply to this post by Coda Highland
On Wed, Aug 27, 2014 at 8:00 PM, Coda Highland <[hidden email]> wrote:

> No, until true would make it loop. until false makes the body of the
> loop execute exactly once.
>
> /s/ Adam
>

While breaking from a 'repeat' would allow you to use break in that
way with the same scoping rules -- I feel like it's not immediately
obvious.  +1 to Thiago?

Reply | Threaded
Open this post in threaded view
|

Re: [Proposal] break do end

Axel Kittenberger
In reply to this post by Soni "They/Them" L.
Reasons against it.

First
It will break existing code in a malicious way.

for k, _ in pairs( foo )
do
   bla
   do
      bla
      if condition
      then
         break
      end
   end
end

this code would have suddendly quite different behaviour with your suggestion applied.#

Second
it can be done with goto.

do
  goto something
  local x = "you'll never see me"
  print(x)
end
::something::
print("something")

Third
We have already a nasty overlap between goto and break doing essentially the same thing (while continue is not allowed to be the essentially same thing for those who would find that convenient). No need to make the overlap worse.


On Thu, Aug 28, 2014 at 4:17 AM, Thiago L. <[hidden email]> wrote:
It would be cool if you could use break with do ... end for some sort of "safe goto"

Example:

do
break
local x = "you'll never see me"
print(x)
end
print("something")

Would print "something"

In 5.2+ we have this:

goto x
local x = ""
::x::
print("something")

But it errors instead of doing the scoping stuff you can do with do ... end

(This is probably not something for lua 5 but for lua 6 if/when we get it... it would probably be less harmful to change goto so that it does an implicit do ... end scoping thingy)


Reply | Threaded
Open this post in threaded view
|

Re: [Proposal] break do end

Dirk Laurie-2
In reply to this post by Soni "They/Them" L.
2014-08-28 4:17 GMT+02:00 Thiago L. <[hidden email]>:

> It would be cool if you could use break with do ... end for some sort of
> "safe goto"
>
> Example:
>
> do
> break
> local x = "you'll never see me"
> print(x)
> end
> print("something")
>
> Would print "something"

If I simply put "for _=1,1" in front of your example, it runs.

I note that you posted this at 23:07 local time :-)

Reply | Threaded
Open this post in threaded view
|

Re: [Proposal] break do end

yanjun@kingsoft.com
In reply to this post by Soni "They/Them" L.
test mail.

Reply | Threaded
Open this post in threaded view
|

Re: [Proposal] break do end

Soni "They/Them" L.
In reply to this post by Axel Kittenberger

On 28/08/14 04:09 AM, Axel Kittenberger wrote:
Reasons against it.

First
It will break existing code in a malicious way.

for k, _ in pairs( foo )
do
   bla
   do
      bla
      if condition
      then
         break
      end
   end
end

this code would have suddendly quite different behaviour with your suggestion applied.#
Can we change goto and labels to do an implicit do...end, then?

Second
it can be done with goto.

do
  goto something
  local x = "you'll never see me"
  print(x)
end
::something::
print("something")

Third
We have already a nasty overlap between goto and break doing essentially the same thing (while continue is not allowed to be the essentially same thing for those who would find that convenient). No need to make the overlap worse.


On Thu, Aug 28, 2014 at 4:17 AM, Thiago L. <[hidden email]> wrote:
It would be cool if you could use break with do ... end for some sort of "safe goto"

Example:

do
break
local x = "you'll never see me"
print(x)
end
print("something")

Would print "something"

In 5.2+ we have this:

goto x
local x = ""
::x::
print("something")

But it errors instead of doing the scoping stuff you can do with do ... end

(This is probably not something for lua 5 but for lua 6 if/when we get it... it would probably be less harmful to change goto so that it does an implicit do ... end scoping thingy)



Reply | Threaded
Open this post in threaded view
|

Re: [Proposal] break do end

Axel Kittenberger
> Can we change goto and labels to do an implicit do...end, then?

in my opinion horrible as well. It would make a goto hell only worse. Take following code:

a = "foo"
::somelabel::
local a = "bar"
if condion then goto somelabel end
print( a )

What do you expect a to be?