[e-lang] Why aren't guards allowed on forward declarations?

David Hopwood david.hopwood at industrial-designers.co.uk
Fri Sep 28 10:47:22 EDT 2007


Mark Miller wrote:
> On 9/26/07, David Hopwood <david.hopwood at industrial-designers.co.uk> wrote:
>> Kevin Reid wrote:
>>> On Sep 26, 2007, at 16:57, David Hopwood wrote:
>>>> Kevin Reid wrote:
>>>>> On Sep 26, 2007, at 16:20, David Hopwood wrote:
>>>>>>    def succeeded :boolean
>>>>> (Syntactic note: Forward declarations may not have guards.)
>>>> Any good reason for this? It seems as though the semantics would be
>>>> clear.
> 
> I just talked to Kevin and Dean about this and came up with a clearer
> reason why this is disallowed.
> 
> In general in E, when a guarded declaration appears such as
> 
>     def succeeded :boolean := expr
> 
> any code for which the defined variable is in scope is guaranteed that
> it will hold a value of the type the guard guarantees. For example, if
> expr produces a non-boolean, an exception will be thrown, preventing
> execution of the code for which the succeeded variable would have been
> in scope.

Ah, I see.

If using backtracking exceptions [*], then the exception caused by trying
to access a forward-declared variable before it is given a value would
undo side effects performed in that scope. In the absence of side effects
that can't be undone (e.g. synchronous I/O), this would give essentially
the same guarantee as normally implied by the guard notation. So when I
explain backtracking exceptions in more detail, I will propose allowing
guards on forward declarations again.


[*] discussed briefly in
    <http://www.eros-os.org/pipermail/e-lang/2007-January/011814.html>

-- 
David Hopwood <david.hopwood at industrial-designers.co.uk>



More information about the e-lang mailing list