octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Should "continue" be dynamically or lexically scoped?


From: Rik
Subject: Re: Should "continue" be dynamically or lexically scoped?
Date: Mon, 25 Mar 2019 21:05:02 -0700

On 03/25/2019 02:27 PM, address@hidden wrote:
Subject:
Should "continue" be dynamically or lexically scoped?
From:
Andrew Janke <address@hidden>
Date:
03/25/2019 02:27 PM
To:
octave-maintainers <address@hidden>
List-Post:
<mailto:address@hidden>
Content-Transfer-Encoding:
8bit
Precedence:
list
MIME-Version:
1.0
Message-ID:
<address@hidden>
Content-Type:
text/plain; charset=utf-8; format=flowed
Message:
5

Hi folks,

A somewhat philosophical language design question for you: Should while/for loops' "continue" be dynamically or lexically scoped? How about "break"?

I asked this on the bug tracker at https://savannah.gnu.org/bugs/?55995 and Rik sent me over here to get a bigger audience.

The current situation is this: continue is dynamically scoped, but break is lexically scoped. This means that a break can only be used inside the text of an actual for/while loop, in the same function that defines it. But you can call continue anywhere, and it will look up the function call stack and affect the execution of a for/while loop in a calling function.


Personally, I lean towards "continue" being lexically scoped, so you can always see where it happens while you're looking at the source code of the function that contains the for loop. Non-local affects on control structures are harder to understand and debug. (This is why some developers dislike exceptions.)

I tend to agree that it makes understanding flow control very difficult.  As another modest argument in its favor, Matlab supports lexical rather than dynamic scoping for "continue".  On the other hand, there are languages, like Perl which I tested, which do allow this.  I think it makes even less sense though to have "break" be lexically scoped and "continue" be dynamically scoped.  It seems like the loop keywords should at least all be treated in the same fashion.

--Rik


reply via email to

[Prev in Thread] Current Thread [Next in Thread]