[bitc-dev] OCaml syntax question
David-Sarah Hopwood
david.hopwood at industrial-designers.co.uk
Fri Mar 6 08:33:22 EST 2009
Jonathan S. Shapiro wrote:
> On Thu, Mar 5, 2009 at 10:30 AM, Geoffrey Irving <irving at naml.us> wrote:
>> On Thu, Mar 5, 2009 at 6:17 AM, Jonathan S. Shapiro <shap at eros-os.com> wrote:
>>> Let me start over. The issue is that the following input to ocaml
>>> produces 3 when it should produce an unbound reference error (x should
>>> be unbound in "x + 2").
>>>
>>> # let x = 1 in x; let y = x + 2 in y;;
>>> - : int = 3
>>>
>>> The problem is that the *following* expression is equivalent and
>>> *terribly* confusing:
>>>
>>> # let x = 1 in begin x end; let y = x + 2 in y;;
>>> - : int = 3
>>>
>>> The desired behavior can apparently be obtained only with begin/end or
>>> parenthesis:
>>>
>>> # (let x = 1 in x); let y = x + 2 in y;;
>>> Unbound value x
>> How is this different from C?
>
> The difference is seen in the second case:
>
> # let x = 1 in begin x end; let y = x + 2 in y;;
>
> In EVERY other language I can think of, that begin/end pair would
> define the scope of the let, [...]
Why? The begin..end delimits only the use of x, not the let.
> and because of that history, it is guaranteed to be read that way
> by humans.
I didn't read it that way. I agree that 'let' should be explicitly
delimited, but I don't think this example shows the point.
--
David-Sarah Hopwood ⚥
More information about the bitc-dev
mailing list