On Thu, Mar 5, 2009 at 6:17 AM, Jonathan S. Shapiro <[email protected]> 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?
int x = 1;
x;
int y = x + 2;
y;
vs.
int x = 1;
{
x;
}
int y = x + 2;
y;
vs.
{
int x = 1;
x;
}
int y = x + 2; // error
y;
Most of the constructs involving ";" that one ends up writing in ocaml
look something like
let x in f(1) in
let y = g(x) in
let z = h(y) in
print_string "blah";
print_string "another string"
let w = q(z) in
...
It would get annoying very quickly if variables went out of scope as
soon as you added a semicolor, just like it would in C.
> There are many examples even in the ocaml reference manual that are
> indented incorrectly w.r.t. the actual binding rules. The sheer number
> of these errors in the document strongly argues that scoping forms
> should have a syntactic end marker. It might be okay if that turns out
> to be indentation, but it needs to be something.
Do any of those examples have actual errors? Having a variable
syntactically live for slightly longer than one might imagine isn't
much of a problem in a garbage collected language with no finalizers.
Geoffrey
_______________________________________________
bitc-dev mailing list
[email protected]
http://www.coyotos.org/mailman/listinfo/bitc-dev