Skip to content

Allow shortcut for extension on semicolons#508

Merged
lpw25 merged 1 commit intotrunkfrom
unknown repository
Jul 18, 2016
Merged

Allow shortcut for extension on semicolons#508
lpw25 merged 1 commit intotrunkfrom
unknown repository

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented Mar 15, 2016

Similarly to what is done for keywords.

The syntax is:

  <expr> ;%foo <expr>

and is a shortcut for: [%foo <expr> ; <expr>]

The rationale is to have the equivalent of the normal semicolon when
writing ml code using a monadic let%foo.

;% is currently a syntax error, so it doesn't break anything

@Drup
Copy link
Copy Markdown
Contributor

Drup commented Mar 15, 2016

If we are going this way, adding shortcuts on symbols (and I'm not convinced that we should), we might as well do it for all the symbols....

@ghost
Copy link
Copy Markdown
Author

ghost commented Mar 15, 2016

That would be a breaking change, so I don't think that's worth it. On the contrary we have a real use case for the semicolon and it doesn't break anything

@alainfrisch
Copy link
Copy Markdown
Contributor

Do we really need to introduce a new token? Whitespace is allowed between the keyword and "%", so it would be better if it would as well between ";" and "%"; or does it introduce some parsing problems?

@trefis
Copy link
Copy Markdown
Contributor

trefis commented Mar 15, 2016

It doesn't seem to introduce any conflict.
Did [%, [@@@, etc introduce parsing problems?

@bobzhang
Copy link
Copy Markdown
Member

how is it different from begin%foo e1; e2 end

@ghost
Copy link
Copy Markdown
Author

ghost commented Mar 15, 2016

@bobzhang, it's the same, just shorter. Basically the first form is nicer than the second:

(* first form *)
f x ;%bind
g y ;%bind
return ()

(* second form *)
begin%bind
  f x;
  begin%bind
    g y;
    return
  end
end

@alainfrisch
Copy link
Copy Markdown
Contributor

You could probably extend the interpretation of %bind to all immediately nested sequences, allowing to write:

begin%bind
  f x;
  g y;
  return ()
end

@ghost
Copy link
Copy Markdown
Author

ghost commented Mar 15, 2016

Well, you'd need to interpret all the let as well, as we often mix let ... in and ;, and that would be like the haskell do-notation. In practice, in real code we often have a mix of let, let%bind and ; at the same level so having a block bind would introduce more visual nesting

Similarly to what is done for keywords. The syntax is:

  <expr> ;%foo <expr>

and is a shortcut for: [%foo <expr> ; <expr>]

The rationale is to have the equivalent of the normal semicolon when
writing ml code using a monadic let%foo
@damiendoligez damiendoligez added this to the 4.04 milestone Mar 31, 2016
@bobzhang
Copy link
Copy Markdown
Member

@diml, can you also do this { %ext a = 3; b = 4}, it is very similar to your extension here, I have a use case for it too, thanks!

@lpw25
Copy link
Copy Markdown
Contributor

lpw25 commented Jul 14, 2016

Is anyone strongly opposed to this?

As the change is trivial and only effects what syntax ppx writers can use, I'll probably merge it in a couple of days if no one objects.

@lpw25 lpw25 merged commit d6c72fc into ocaml:trunk Jul 18, 2016
camlspotter pushed a commit to camlspotter/ocaml that referenced this pull request Oct 17, 2017
Allow shortcut for extension on semicolons
@bluddy
Copy link
Copy Markdown
Contributor

bluddy commented Nov 15, 2017

Just noticed this! This is great, especially if we adopt shortcuts like ;%b rather than using 'bind'. Still a little messy looking, but not too bad.

@hcarty
Copy link
Copy Markdown
Member

hcarty commented Nov 15, 2017

@bluddy I started a patch for Lwt's ppx here which we ended up closing due to a mixture of backwards-compatibility concerns and generally unpleasant-looking syntax with ;%lwt. The implementation was fairly straightforward though and should be simple enough to experiment with in other contexts.

@bluddy
Copy link
Copy Markdown
Contributor

bluddy commented Nov 15, 2017

I agree that ;%lwt isn't too appealing. ;%l is a little better, but really, I'd much prefer it if ;% was possible. Is there anything that theoretically prevents an empty string extension? In cases where brevity is desired, this could really be a game changer, because it's almost like a simple operator.

mshinwell pushed a commit to mshinwell/ocaml that referenced this pull request Jun 30, 2021
Shows the internal structure of the Patricia tree for debugging
purposes.

Also added `print_debug` to the `Identifiable.Map` module type, the
default implementation being just `print`.
stedolan pushed a commit to stedolan/ocaml that referenced this pull request May 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants