Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006782OCamllexing and parsingpublic2015-02-17 06:552017-03-16 01:50
Reporterfrisch 
Assigned To 
PrioritynormalSeverityfeatureReproducibilityhave not tried
StatusacknowledgedResolutionopen 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0006782: Support "obj # (meth arg1 ... argn)"
DescriptionSince method call binds more tightly than function application, it is inconvenient to chain method calls with arguments:

  (((f x0) # m1 x1) # m2 x2) # m3 x3

which would be written "f(x0).m1(x1).m2(x2).m3(x3)" in many other languages.

We have been using the following syntactic variant at LexiFi for some time:

  (f x0) # (m1 x1) # (m2 x2) # (m3 x3)

and I'd like to propose it for upstream inclusion.

This can be implemented by one extra rule in parser.mly:

| simple_expr SHARP LPAREN method_label simple_labeled_expr_list RPAREN
      { mkexp (Pexp_apply(mkexp(Pexp_send($1, $4)), List.rev $5)) }

(or perhaps some extra work so that the location of the Pexp_send node covers only "obj # (meth").

One counterargument is that it's a new use of parentheses, and they don't even correspond to an actual subtree of the AST. But I don't see a better syntax.

Note: 0006583 is a proposal to let js_of_ocaml's new ppx support use the syntax "obj ## meth arg" for Javascript method invocation, and in Javascript, chaining method calls is quite common. The proposal is to consider ## as a custom operator, which means that "obj ## (meth arg)" could already be supported by the ppx, and Drup told me that he indeed plans to do so. Keeping the syntactic similarity between calls of Javascript methods and normal methods calls in OCaml is an extra argument for the present proposal about "obj # (meth arg)".
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0013300)
lpw25 (developer)
2015-02-17 16:16

> (f x0) # (m1 x1) # (m2 x2) # (m3 x3)

I don't think I have any alternative suggestions (other than leave things as they are), but I have to say that I really dislike that syntax.
(0013308)
doligez (administrator)
2015-02-18 23:57

A location with mismatched parentheses? That's asking for trouble, don't do that.

Other than that, the feature seems reasonable.
(0017686)
garrigue (manager)
2017-03-16 01:50

The only solution I see would be to introduce a new infix pseudo-operator.
Something like
  f x0 |# m1 x1 |# m2 x2 |# m3 x3
looks fine, reminiscent of the |> notation.
The question is whether we're ready to consume one more precious lexeme to correct a bad choice in priorities.

- Issue History
Date Modified Username Field Change
2015-02-17 06:55 frisch New Issue
2015-02-17 16:16 lpw25 Note Added: 0013300
2015-02-18 23:57 doligez Note Added: 0013308
2015-02-18 23:57 doligez Status new => acknowledged
2015-02-18 23:57 doligez Target Version => 4.03.0+dev / +beta1
2015-12-02 16:45 frisch Target Version 4.03.0+dev / +beta1 => later
2017-02-23 16:36 doligez Category OCaml general => -OCaml general
2017-03-01 14:20 doligez Category -OCaml general => lexing and parsing
2017-03-01 14:20 doligez Target Version later =>
2017-03-16 01:50 garrigue Note Added: 0017686


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker