caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: Revised syntax question
@ 2000-09-26 14:58 Gerard Huet
  2000-09-26 17:15 ` Brian Rogoff
  2000-09-27  5:50 ` Daniel de Rauglaudre
  0 siblings, 2 replies; 7+ messages in thread
From: Gerard Huet @ 2000-09-26 14:58 UTC (permalink / raw)
  To: Brian Rogoff, caml-list

At 09:34 25/09/00 -0700, Brian Rogoff wrote:
>Hi,
>    I have an issue with the Revised syntax (from OCaml P4, with URL 
>http://caml.inria.fr/camlp4/manual/camlp4023.html). 
>
>How about 
>
>    do e1; e2; e3; done e4
>
>and change while/for to be consistent with this and return a value 
>in done?  
>
>    while e1 
>      do e2; 
>    done e3
>
>    for i = e1 to e2 do e3; done ()
>
>This saves a keyword "return" and looks a bit more consistent, though
>maybe a touch noisier when you don't return a value from a loop. Anyone 
>using Revised have a different opinion?
>
>-- Brian

I hate this return, and actually I do not like this dangling e4. Every 
imperative programming language I used had a list of statements construct,
and from LISP onwards we know how to mix imperative statements and values
(good old progn !). Semantic ayatollahs notwithstanding, it makes perfect
sense to interpret the sequence (s1 ; s2 ; ... ; sn) with operator ";" piping
the state of its first argument into the second one, and returning the value
of the second one. Furthermore it is consistent with the rest of the syntax
to use good old parentheses as begin-end brackets. All you need is to
EXTEND the revised syntax with a 5 line entry for expr at LEVEL "simple".

I usually indent my code
    ( statement 1
    ; statement 2
    ...
    ; statement n
    )
nicely symmetrical to 
    match foo with   (or fun or try expr with)
      [ case 1
      | case 2
      ...
      | case n
      ]
and I read "begin" for "(", "then" for ";" and "end" for ")", although
sometimes I say "returned" when I want to emphasise the returned value.

I'll be glad to communicate the 5 lines of camlp4 to whoever wants to try
this syntax; but all flame should be sent to /dev/null

Cheers,
Gérard





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

* Re: Revised syntax question
  2000-09-26 14:58 Revised syntax question Gerard Huet
@ 2000-09-26 17:15 ` Brian Rogoff
  2000-09-27  5:50 ` Daniel de Rauglaudre
  1 sibling, 0 replies; 7+ messages in thread
From: Brian Rogoff @ 2000-09-26 17:15 UTC (permalink / raw)
  To: Gerard Huet; +Cc: caml-list

On Tue, 26 Sep 2000, Gerard Huet wrote:
[snip]
> I hate this return, and actually I do not like this dangling e4. Every 
> imperative programming language I used had a list of statements construct,
> and from LISP onwards we know how to mix imperative statements and values
> (good old progn !). Semantic ayatollahs notwithstanding, it makes perfect
> sense to interpret the sequence (s1 ; s2 ; ... ; sn) with operator ";" piping
> the state of its first argument into the second one, and returning the value
> of the second one. Furthermore it is consistent with the rest of the syntax
> to use good old parentheses as begin-end brackets. 

I think you mentioned this approach before in an e-mail. Let's discuss
it. Out of curiosity, why do you hate the return form? 

Do you still keep a "do" for loops in your syntax? One of my goals 
was to unify the syntaxes for looping and sequencing a bit. 

Daniel de Rauglaudre also mentioned the issue with "let" in the imperative 
construction. I admit that having a "do ... done e" construct makes 
translation of some of them heavier syntactically. I'm not convinced this 
is necessarily bad, but I'm open to reasoned arguments that it is too
much.

> EXTEND the revised syntax with a 5 line entry for expr at LEVEL "simple".
> 
> I usually indent my code
>     ( statement 1
>     ; statement 2
>     ...
>     ; statement n
>     )
> nicely symmetrical to 
>     match foo with   (or fun or try expr with)
>       [ case 1
>       | case 2
>       ...
>       | case n
>       ]
> and I read "begin" for "(", "then" for ";" and "end" for ")", although
> sometimes I say "returned" when I want to emphasise the returned value.
> 
> I'll be glad to communicate the 5 lines of camlp4 to whoever wants to try
> this syntax; but all flame should be sent to /dev/null

Sure I'm interested. No need for the warning, I don't think a discussion
of Revised syntax will degrade to flames as there probably aren't enough
users. Given that, we have a great opportunity to make the syntax as good 
as can be. I'm not yet wedded to any particular syntax, so I'd be happy
to try yours.

-- Brian



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

* Re: Revised syntax question
  2000-09-26 14:58 Revised syntax question Gerard Huet
  2000-09-26 17:15 ` Brian Rogoff
@ 2000-09-27  5:50 ` Daniel de Rauglaudre
  2000-09-27  9:29   ` Marcin 'Qrczak' Kowalczyk
  2000-09-28  4:36   ` Brian Rogoff
  1 sibling, 2 replies; 7+ messages in thread
From: Daniel de Rauglaudre @ 2000-09-27  5:50 UTC (permalink / raw)
  To: Gerard Huet; +Cc: Brian Rogoff, caml-list

Hi,

On Tue, Sep 26, 2000 at 04:58:33PM +0200, Gerard Huet wrote:

> I hate this return, and actually I do not like this dangling e4.

I don't know what you have against the do...return construct, since we
are in a functional language and this kind of construction separates the
imperative part (do...return) which could (should) be typed "unit" and
the functional part (after the return). My opinion is that in "e1;e2;..;en"
the expression "en" has something different.

I don't agree with the idea that some control is passed from e1 to e2, then
e2 to e3. In sequence, we do "e1", then we forget it, we do e2, we forget it,
and nothing at all runs from e1 to e2.

And if your sequence is only composed of side effects, "en" included,
you can write (it's what I do):
    do e1;e2;..;en; return ()

which appears to me very logical. Just consider "return ()" as the
ending keyword.

   ---

But... but! I don't want to make a business with that. We can talk about
it, but I agree to change that into a completely symmetrical form like the
one you propose if we are numerous enough to accept that form. Besides, there
is the problem of the "let" inside sequences which my form does not allow.

(Explanation: when you write in OCaml syntax:
      e1; e2; let x1 = f1 in e3; e4
actually, this sequence has 3 (not 4) expressions:
      e1; e2; (let x1 = f1 in e3; e4)
since the binding x1 = f1 runs up to e4; in my syntax you have to write:
      do e1; e2; return let x1 = f1 in do e3; return e4
and I recognize it is ugly.)

   ---

What about Michel Mauny's proposition for the sequence:
    do { e1; e2; ... ; en }

The braces remind C language, what is logical, since it is imperative.
The "let" up to the end of the sequence could be represented by "let
binding ;", i.e. ended by just a semicolon instead of "in":
    do { e1; e2; let x1 = f1; e3; e4 }

what would remind the "x1 = f1;" of C.

The while and for constructs could be changed into:

     while e do { e1; ....; en }
     for x = e1 to e2 do { e1; ...; en }

with the same ability to write this "let x = y;"

I can implement that if there are several persons who like it,
because, for the moment, I am used to "do...return ()" in my code, I
wrote a lot of code with it and I don't want to change it if three
days after, people tells me it is uglier.

I can also change my syntax tree to that form and accept
     <:expr< do { e1; ... ; en } >>
as sequence syntax tree.

I consider simple parentheses as not enough "sequence". When a
parenthesis is opened, if the expression is long, there is no way to
know whether it is a sequence or not. There is the same problem with
t-uples but generally, t-uples are shorter than sequences. I consider
that the language should clearly show sequences, even with a loss of
simplicity.

-- 
Daniel de RAUGLAUDRE
daniel.de_rauglaudre@inria.fr
http://cristal.inria.fr/~ddr/



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

* Re: Revised syntax question
  2000-09-27  5:50 ` Daniel de Rauglaudre
@ 2000-09-27  9:29   ` Marcin 'Qrczak' Kowalczyk
  2000-09-28  4:36   ` Brian Rogoff
  1 sibling, 0 replies; 7+ messages in thread
From: Marcin 'Qrczak' Kowalczyk @ 2000-09-27  9:29 UTC (permalink / raw)
  To: caml-list

Tue, 26 Sep 2000 10:15:05 -0700 (PDT), Brian Rogoff <bpr@best.com> pisze:

> Do you still keep a "do" for loops in your syntax? One of my goals 
> was to unify the syntaxes for looping and sequencing a bit.

I thought the primary goal was to make it look like Haskell :-)

Wed, 27 Sep 2000 07:50:12 +0200, Daniel de Rauglaudre <daniel.de_rauglaudre@inria.fr> pisze:

> (Explanation: when you write in OCaml syntax:
>       e1; e2; let x1 = f1 in e3; e4
> actually, this sequence has 3 (not 4) expressions:
>       e1; e2; (let x1 = f1 in e3; e4)
> since the binding x1 = f1 runs up to e4; in my syntax you have to write:
>       do e1; e2; return let x1 = f1 in do e3; return e4
> and I recognize it is ugly.)

Fortunately e3; e4 is not an expression in the revised syntax,
so this syntax would be IMHO nice:

  do e1; e2; let x = f1; e3; return e4

-- 
 __("<  Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.ids.net.pl/
 \__/
  ^^                      SYGNATURA ZASTĘPCZA
QRCZAK



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

* Re: Revised syntax question
  2000-09-27  5:50 ` Daniel de Rauglaudre
  2000-09-27  9:29   ` Marcin 'Qrczak' Kowalczyk
@ 2000-09-28  4:36   ` Brian Rogoff
  2000-09-28 12:01     ` Daniel de Rauglaudre
  1 sibling, 1 reply; 7+ messages in thread
From: Brian Rogoff @ 2000-09-28  4:36 UTC (permalink / raw)
  To: Daniel de Rauglaudre; +Cc: Gerard Huet, caml-list

On Wed, 27 Sep 2000, Daniel de Rauglaudre wrote:
> But... but! I don't want to make a business with that. We can talk about
> it, but I agree to change that into a completely symmetrical form like the
> one you propose if we are numerous enough to accept that form. Besides, there
> is the problem of the "let" inside sequences which my form does not allow.
> 
> (Explanation: when you write in OCaml syntax:
>       e1; e2; let x1 = f1 in e3; e4
> actually, this sequence has 3 (not 4) expressions:
>       e1; e2; (let x1 = f1 in e3; e4)
> since the binding x1 = f1 runs up to e4; in my syntax you have to write:
>       do e1; e2; return let x1 = f1 in do e3; return e4
> and I recognize it is ugly.)

How many times did you bump into this coding, or is it mostly an abstract 
problem? I guess if you are sticking in debug info it is pretty easy to
get it...

> What about Michel Mauny's proposition for the sequence:
>     do { e1; e2; ... ; en }
> 
> The braces remind C language, what is logical, since it is imperative.
> The "let" up to the end of the sequence could be represented by "let
> binding ;", i.e. ended by just a semicolon instead of "in":
>     do { e1; e2; let x1 = f1; e3; e4 }
> 
> what would remind the "x1 = f1;" of C.
> 
> The while and for constructs could be changed into:
> 
>      while e do { e1; ....; en }
>      for x = e1 to e2 do { e1; ...; en }
> 
> with the same ability to write this "let x = y;"

This looks good to me. My criteria involve simplicity, ease of
explanation to beginners, and "just one way to do it", but I also think
that imperative sequences should stick out "just a little" in a mostly 
functional language. This is nice and light, and loses the asymmetry 
that Gerard finds distasteful. As you say it has some syntactic
compatibility with C (and Haskell :) and reduces the keyword count,
though of course Gerard's proposal uses even fewer if we adopt it for
loops too. 

> I can implement that if there are several persons who like it,
> because, for the moment, I am used to "do...return ()" in my code, I
> wrote a lot of code with it and I don't want to change it if three
> days after, people tells me it is uglier.

After thinking about it for two days I still think it looks OK. Maybe wait 
one more? :-)

> I can also change my syntax tree to that form and accept
>      <:expr< do { e1; ... ; en } >>
> as sequence syntax tree.
> 
> I consider simple parentheses as not enough "sequence". When a
> parenthesis is opened, if the expression is long, there is no way to
> know whether it is a sequence or not. There is the same problem with
> t-uples but generally, t-uples are shorter than sequences. I consider
> that the language should clearly show sequences, even with a loss of
> simplicity.

I agree with this, sequences should be a little distinct. I don't know if 
we are at an impasse though, since this is a matter of taste. I can accept
that do/done and do/return are too heavyweight, but does do { e1; ... ; en } 
add too much weight? It's hard to imagine a lighter solution without going
all the way to ( e1; ... ; en ) so there's not much room left for
compromise. I think either is acceptable, and is an improvement over the
current state of affairs.

-- Brian




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

* Re: Revised syntax question
  2000-09-28  4:36   ` Brian Rogoff
@ 2000-09-28 12:01     ` Daniel de Rauglaudre
  0 siblings, 0 replies; 7+ messages in thread
From: Daniel de Rauglaudre @ 2000-09-28 12:01 UTC (permalink / raw)
  To: Brian Rogoff; +Cc: caml-list

Hi,

On Wed, Sep 27, 2000 at 09:36:42PM -0700, Brian Rogoff wrote:

> > since the binding x1 = f1 runs up to e4; in my syntax you have to write:
> >       do e1; e2; return let x1 = f1 in do e3; return e4
> > and I recognize it is ugly.)
> 
> How many times did you bump into this coding, or is it mostly an abstract 
> problem?

No, it is not abstract. I have often the case in my code. Sometimes, I
turn around it, when it is equivalent, by writting:
       let x1 = f1 in do e1; e2; e3; return e4
but it is not really satisfactory.

-- 
Daniel de RAUGLAUDRE
daniel.de_rauglaudre@inria.fr
http://cristal.inria.fr/~ddr/



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

* Revised syntax question
@ 2000-09-25 16:34 Brian Rogoff
  0 siblings, 0 replies; 7+ messages in thread
From: Brian Rogoff @ 2000-09-25 16:34 UTC (permalink / raw)
  To: caml-list

Hi,
    I have an issue with the Revised syntax (from OCaml P4, with URL 
http://caml.inria.fr/camlp4/manual/camlp4023.html). 

How about 

    do e1; e2; e3; done e4

and change while/for to be consistent with this and return a value 
in done?  

    while e1 
      do e2; 
    done e3

    for i = e1 to e2 do e3; done ()

This saves a keyword "return" and looks a bit more consistent, though
maybe a touch noisier when you don't return a value from a loop. Anyone 
using Revised have a different opinion?

-- Brian

    



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

end of thread, other threads:[~2000-09-28 14:58 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-09-26 14:58 Revised syntax question Gerard Huet
2000-09-26 17:15 ` Brian Rogoff
2000-09-27  5:50 ` Daniel de Rauglaudre
2000-09-27  9:29   ` Marcin 'Qrczak' Kowalczyk
2000-09-28  4:36   ` Brian Rogoff
2000-09-28 12:01     ` Daniel de Rauglaudre
  -- strict thread matches above, loose matches on Subject: below --
2000-09-25 16:34 Brian Rogoff

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).