caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* camlp4 scope issue
@ 2006-10-25 15:36 Serge Aleynikov
  2006-10-25 19:42 ` [Caml-list] " Dmitri Boulytchev
  0 siblings, 1 reply; 7+ messages in thread
From: Serge Aleynikov @ 2006-10-25 15:36 UTC (permalink / raw)
  To: caml-list

Hi,

In the test program below in my understanding the 'y' variable should be
out of scope in the printf statement, but apparently it's not.  The
compiler version is 3.09.3.

$ cat tst.ml
value f z = z + 1;

let x = 1 in do {
   let y = f x in ();
   Printf.printf "y should be out of scope, but it's not: y = %d\n" y
};

$ ocamlc -o tst -pp camlp4r tst.ml
$ ./tst
y should be out of scope, but it's not: y = 2


Any idea why?

-- 
Serge Aleynikov
Routing R&D, IDT Telecom
Tel: +1 (973) 438-3436
Fax: +1 (973) 438-1464


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] camlp4 scope issue
  2006-10-25 19:42 ` [Caml-list] " Dmitri Boulytchev
@ 2006-10-25 16:04   ` Serge Aleynikov
  2006-10-25 16:17     ` Nicolas Pouillard
  2006-10-25 20:19     ` Dmitri Boulytchev
  0 siblings, 2 replies; 7+ messages in thread
From: Serge Aleynikov @ 2006-10-25 16:04 UTC (permalink / raw)
  To: Dmitri Boulytchev, bhurt; +Cc: caml-list

Perhaps I am misunderstanding the meaning of ";" in the revised syntax, 
however, the 6.2 chapter 
(http://caml.inria.fr/pub/docs/manual-camlp4/manual007.html) says that:

do { e1; e2; e3; e4 }

is an iterative sequence of expressions, whereas "let ... in" is 
reserved for local constructs.

If so, wouldn't the scope of y in

let y = 1 in do { a; b; c };

be different from:

let y = 1 in a; b; c;

Or else how to we indicate in the *revised syntax* the boundary of the 
"let ... in" scope?

Serge

Dmitri Boulytchev wrote:
>     That's ok - semicolon does not restict the scope since it plays role
> of a binary operation, not a statement delimiter. So in your example
> 
>     (); Printf.printf "y should be out of scope, but it's not: y = %d\n" y
>    
>     is a while scope for let-binding.
> 
>     Best regards,
>     Dmitri Boulytchev,
>     St.Petersburg State University.
> 
> 
>> Hi,
>>
>> In the test program below in my understanding the 'y' variable should be
>> out of scope in the printf statement, but apparently it's not.  The
>> compiler version is 3.09.3.
>>
>> $ cat tst.ml
>> value f z = z + 1;
>>
>> let x = 1 in do {
>>   let y = f x in ();
>>   Printf.printf "y should be out of scope, but it's not: y = %d\n" y
>> };
>>
>> $ ocamlc -o tst -pp camlp4r tst.ml
>> $ ./tst
>> y should be out of scope, but it's not: y = 2
>>
>>
>> Any idea why?
>>
> 
> 


-- 
Serge Aleynikov
Routing R&D, IDT Telecom
Tel: +1 (973) 438-3436
Fax: +1 (973) 438-1464


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] camlp4 scope issue
  2006-10-25 16:04   ` Serge Aleynikov
@ 2006-10-25 16:17     ` Nicolas Pouillard
  2006-10-25 16:35       ` Serge Aleynikov
  2006-10-25 20:19     ` Dmitri Boulytchev
  1 sibling, 1 reply; 7+ messages in thread
From: Nicolas Pouillard @ 2006-10-25 16:17 UTC (permalink / raw)
  To: Serge Aleynikov; +Cc: Dmitri Boulytchev, bhurt, caml-list

On 10/25/06, Serge Aleynikov <serge@hq.idt.net> wrote:
> Perhaps I am misunderstanding the meaning of ";" in the revised syntax,
> however, the 6.2 chapter
> (http://caml.inria.fr/pub/docs/manual-camlp4/manual007.html) says that:
>
> do { e1; e2; e3; e4 }
>
> is an iterative sequence of expressions, whereas "let ... in" is
> reserved for local constructs.
>
> If so, wouldn't the scope of y in
>
> let y = 1 in do { a; b; c };
>
> be different from:
>
> let y = 1 in a; b; c;
>
> Or else how to we indicate in the *revised syntax* the boundary of the
> "let ... in" scope?

It's not a bug it's a feature :)

But a not documented one.

Inside a << do { ... } >> you can use << let var = expr1; expr2 >>
like << let var = expr1 in expr2 >>.

The main goal is to facilitate imperative coding inside a << do {} >>:

do {
  let x = 42;
  do_that_on x;
  let y = x + 2;
  play_with y;
}

That's nice but undocumented :(

Without such a syntax the regular one will make you nest do { ... } notations.

do {
  foo 1;
  let x = 43 in do {
     bar x;
  };
  (* x should be out of the scope *)
}

Alas << let ... in >> and << let ... ; >> have the same semantics
inside a << do { ... } >> what I regret because << let ... in >> is
not local anymore.

In plain OCaml it's different since << ; >> is a binary operator so
you must see << let a = () in a; a >> like << let a = () in (a; a) >>.

Hope this helps...

Best regards,

-- 
Nicolas Pouillard


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] camlp4 scope issue
  2006-10-25 20:19     ` Dmitri Boulytchev
@ 2006-10-25 16:21       ` Mike Lin
  0 siblings, 0 replies; 7+ messages in thread
From: Mike Lin @ 2006-10-25 16:21 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 2426 bytes --]

I would like to take this opportunity to plug ocaml+twt. Relieve your
suffering...
http://people.csail.mit.edu/mikelin/ocaml+twt/

On 10/25/06, Dmitri Boulytchev <db@tepkom.ru> wrote:
>
>     The revised syntax description you are referring to is quite
> informal so I'd rather trust the compiler :)
>     You may restict the scope of a binding in a way its usual done in
> other languages: by
>
>     do {let y = 1 in a}; b; c;
>
>     in revised or by
>
>     (let y = 1 in a); b; c;
>
>     in  standard syntax.
>
>     BR,
>     DB.
>
> > Perhaps I am misunderstanding the meaning of ";" in the revised
> > syntax, however, the 6.2 chapter
> > (http://caml.inria.fr/pub/docs/manual-camlp4/manual007.html) says that:
> >
> > do { e1; e2; e3; e4 }
> >
> > is an iterative sequence of expressions, whereas "let ... in" is
> > reserved for local constructs.
> >
> > If so, wouldn't the scope of y in
> >
> > let y = 1 in do { a; b; c };
> >
> > be different from:
> >
> > let y = 1 in a; b; c;
> >
> > Or else how to we indicate in the *revised syntax* the boundary of the
> > "let ... in" scope?
> >
> > Serge
> >
> > Dmitri Boulytchev wrote:
> >
> >>     That's ok - semicolon does not restict the scope since it plays
> role
> >> of a binary operation, not a statement delimiter. So in your example
> >>
> >>     (); Printf.printf "y should be out of scope, but it's not: y =
> >> %d\n" y
> >>        is a while scope for let-binding.
> >>
> >>     Best regards,
> >>     Dmitri Boulytchev,
> >>     St.Petersburg State University.
> >>
> >>
> >>> Hi,
> >>>
> >>> In the test program below in my understanding the 'y' variable
> >>> should be
> >>> out of scope in the printf statement, but apparently it's not.  The
> >>> compiler version is 3.09.3.
> >>>
> >>> $ cat tst.ml
> >>> value f z = z + 1;
> >>>
> >>> let x = 1 in do {
> >>>   let y = f x in ();
> >>>   Printf.printf "y should be out of scope, but it's not: y = %d\n" y
> >>> };
> >>>
> >>> $ ocamlc -o tst -pp camlp4r tst.ml
> >>> $ ./tst
> >>> y should be out of scope, but it's not: y = 2
> >>>
> >>>
> >>> Any idea why?
> >>>
> >>
> >>
> >
> >
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>

[-- Attachment #2: Type: text/html, Size: 3953 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] camlp4 scope issue
  2006-10-25 16:17     ` Nicolas Pouillard
@ 2006-10-25 16:35       ` Serge Aleynikov
  0 siblings, 0 replies; 7+ messages in thread
From: Serge Aleynikov @ 2006-10-25 16:35 UTC (permalink / raw)
  To: Nicolas Pouillard; +Cc: caml-list

Ugh!  Thank you for clarifying this, as it was driving me insane in 
trying to figure out what the revised construct was *supposed to do* 
rather than what it *did*.

Not sure if this is a proper place to ask, but would it be possible to 
document this feature?

Frankly, in presence of the << value ...; >> construct, I don't see the 
benefit behind << let ... ; >> inside the << do { ... } >> clause other 
than causing confusion.  Though I realize that people might have a 
different view of this...

Regards,

Serge

-- 
Serge Aleynikov
Routing R&D, IDT Telecom
Tel: +1 (973) 438-3436
Fax: +1 (973) 438-1464


Nicolas Pouillard wrote:
> On 10/25/06, Serge Aleynikov <serge@hq.idt.net> wrote:
>> Perhaps I am misunderstanding the meaning of ";" in the revised syntax,
>> however, the 6.2 chapter
>> (http://caml.inria.fr/pub/docs/manual-camlp4/manual007.html) says that:
>>
>> do { e1; e2; e3; e4 }
>>
>> is an iterative sequence of expressions, whereas "let ... in" is
>> reserved for local constructs.
>>
>> If so, wouldn't the scope of y in
>>
>> let y = 1 in do { a; b; c };
>>
>> be different from:
>>
>> let y = 1 in a; b; c;
>>
>> Or else how to we indicate in the *revised syntax* the boundary of the
>> "let ... in" scope?
> 
> It's not a bug it's a feature :)
> 
> But a not documented one.
> 
> Inside a << do { ... } >> you can use << let var = expr1; expr2 >>
> like << let var = expr1 in expr2 >>.
> 
> The main goal is to facilitate imperative coding inside a << do {} >>:
> 
> do {
>  let x = 42;
>  do_that_on x;
>  let y = x + 2;
>  play_with y;
> }
> 
> That's nice but undocumented :(
> 
> Without such a syntax the regular one will make you nest do { ... } 
> notations.
> 
> do {
>  foo 1;
>  let x = 43 in do {
>     bar x;
>  };
>  (* x should be out of the scope *)
> }
> 
> Alas << let ... in >> and << let ... ; >> have the same semantics
> inside a << do { ... } >> what I regret because << let ... in >> is
> not local anymore.
> 
> In plain OCaml it's different since << ; >> is a binary operator so
> you must see << let a = () in a; a >> like << let a = () in (a; a) >>.
> 
> Hope this helps...
> 
> Best regards,
> 




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] camlp4 scope issue
  2006-10-25 15:36 camlp4 scope issue Serge Aleynikov
@ 2006-10-25 19:42 ` Dmitri Boulytchev
  2006-10-25 16:04   ` Serge Aleynikov
  0 siblings, 1 reply; 7+ messages in thread
From: Dmitri Boulytchev @ 2006-10-25 19:42 UTC (permalink / raw)
  To: Serge Aleynikov; +Cc: caml-list

    That's ok - semicolon does not restict the scope since it plays role
of a binary operation, not a statement delimiter. So in your example

    (); Printf.printf "y should be out of scope, but it's not: y = %d\n" y
   
    is a while scope for let-binding.

    Best regards,
    Dmitri Boulytchev,
    St.Petersburg State University.


> Hi,
>
> In the test program below in my understanding the 'y' variable should be
> out of scope in the printf statement, but apparently it's not.  The
> compiler version is 3.09.3.
>
> $ cat tst.ml
> value f z = z + 1;
>
> let x = 1 in do {
>   let y = f x in ();
>   Printf.printf "y should be out of scope, but it's not: y = %d\n" y
> };
>
> $ ocamlc -o tst -pp camlp4r tst.ml
> $ ./tst
> y should be out of scope, but it's not: y = 2
>
>
> Any idea why?
>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] camlp4 scope issue
  2006-10-25 16:04   ` Serge Aleynikov
  2006-10-25 16:17     ` Nicolas Pouillard
@ 2006-10-25 20:19     ` Dmitri Boulytchev
  2006-10-25 16:21       ` Mike Lin
  1 sibling, 1 reply; 7+ messages in thread
From: Dmitri Boulytchev @ 2006-10-25 20:19 UTC (permalink / raw)
  To: Serge Aleynikov, caml-list

    The revised syntax description you are referring to is quite
informal so I'd rather trust the compiler :)
    You may restict the scope of a binding in a way its usual done in
other languages: by

    do {let y = 1 in a}; b; c;

    in revised or by

    (let y = 1 in a); b; c;

    in  standard syntax.

    BR,
    DB.

> Perhaps I am misunderstanding the meaning of ";" in the revised
> syntax, however, the 6.2 chapter
> (http://caml.inria.fr/pub/docs/manual-camlp4/manual007.html) says that:
>
> do { e1; e2; e3; e4 }
>
> is an iterative sequence of expressions, whereas "let ... in" is
> reserved for local constructs.
>
> If so, wouldn't the scope of y in
>
> let y = 1 in do { a; b; c };
>
> be different from:
>
> let y = 1 in a; b; c;
>
> Or else how to we indicate in the *revised syntax* the boundary of the
> "let ... in" scope?
>
> Serge
>
> Dmitri Boulytchev wrote:
>
>>     That's ok - semicolon does not restict the scope since it plays role
>> of a binary operation, not a statement delimiter. So in your example
>>
>>     (); Printf.printf "y should be out of scope, but it's not: y =
>> %d\n" y
>>        is a while scope for let-binding.
>>
>>     Best regards,
>>     Dmitri Boulytchev,
>>     St.Petersburg State University.
>>
>>
>>> Hi,
>>>
>>> In the test program below in my understanding the 'y' variable
>>> should be
>>> out of scope in the printf statement, but apparently it's not.  The
>>> compiler version is 3.09.3.
>>>
>>> $ cat tst.ml
>>> value f z = z + 1;
>>>
>>> let x = 1 in do {
>>>   let y = f x in ();
>>>   Printf.printf "y should be out of scope, but it's not: y = %d\n" y
>>> };
>>>
>>> $ ocamlc -o tst -pp camlp4r tst.ml
>>> $ ./tst
>>> y should be out of scope, but it's not: y = 2
>>>
>>>
>>> Any idea why?
>>>
>>
>>
>
>


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2006-10-25 16:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-25 15:36 camlp4 scope issue Serge Aleynikov
2006-10-25 19:42 ` [Caml-list] " Dmitri Boulytchev
2006-10-25 16:04   ` Serge Aleynikov
2006-10-25 16:17     ` Nicolas Pouillard
2006-10-25 16:35       ` Serge Aleynikov
2006-10-25 20:19     ` Dmitri Boulytchev
2006-10-25 16:21       ` Mike Lin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).