np / ling

LINear LaNGuage: Type Theory and Process Calculi for Distributed and High-precision programming
BSD 3-Clause "New" or "Revised" License
108 stars 10 forks source link

Alternative syntax with a classic memory read/write style #8

Open np opened 8 years ago

np commented 8 years ago

An example:

cmd_syntax_example =
  cmd(i : [?Int, ?Int], o : !Int)
     i[i0,i1]
     ( (x : Int) := @i0
     | (y : Int) := @i1).
     @o := (x + y)

Essentially recv c (x : A) becomes (x : A) := @c and send c t becomes @c := t.

So far the use of @ conflicts with its use to embed terms but so far I think it goes nicely with the idea of a location.

A more aggressive change would be to always write channels with a @ symbol. This could help making things more obvious at many levels but also look noisy and reminds of too many scripting languages...

diakopter commented 8 years ago

lol

and reminds of too many scripting languages...

On Thu, Oct 8, 2015 at 6:25 AM, Nicolas Pouillard notifications@github.com wrote:

An example:

cmd_syntax_example = cmd(i : [?Int, ?Int], o : !Int) i[i0,i1](%28x : Int%29 := @i0 | %28y : Int%29 := @i1). @o := (x + y)

Essentially recv c (x : A) becomes (x : A) := @c and send c t becomes @c := t.

So far the use of @ conflicts with its use to embed terms but so far I think it goes nicely with the idea of a location.

A more aggressive change would be to always write channels with a @ symbol. This could help making things more obvious at many levels but also look noisy and reminds of too many scripting languages...

— Reply to this email directly or view it on GitHub https://github.com/np/ling/issues/8.

Sent by an Internet

np commented 8 years ago

Here is an alternative proposal reusing ! and ? instead of @. Moreover combined with issue #16, #17, and #18, a receive action is presented as a let binding of a recv term.

The example could then be:

cmd_syntax_example =
  cmd(i : [?Int, ?Int], o : !Int)
     i[i0,i1]
     ( let x = (?io : Int)
     | let y : Int = ?i1).
     !o := x + y

or shorter:

cmd_syntax_example =
  cmd(i : [?Int, ?Int], o : !Int)
     i[i0,i1]
     !o := (?io : Int) + (?i1 : Int)
np commented 8 years ago

I'm leaning towards following the syntax of Go for sending/receiving on channels.

The idea is to use "<-" as the visual marker for what goes in or out of a channel. I want to keep using "let" for variables (as opposed to channels). However I think it was wrong to use "=" for a receive even when embedded in a term. I think we should keep "=" as the visual marker for permanent definitions for which one can freely substitute away the definition.

In summary here is my new proposal:

For the new syntax for #16, we should not use "=" for the reason mentioned above. We could extend the syntax of receive but this not really good to explain. I'm leaning towards using "<=" as a mix: let x : A <= term.

For instance let x : Int <= (<-i0) + (<-i1) is translated to (let xi0 : Int <- i0 | let xi1 : Int <- i1). let x : Int = xi0 + xi1. Here again the marker "<=" tells you that this is going to introduce some receives with "<-" and one definition with "=".

taruti commented 8 years ago

<= could cause confusion with "less-or-equal".