Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why doesn't OPA syntax allow optional parenthesis when functions accept a single argument? #28

Closed
jordwalke opened this issue Jan 13, 2012 · 3 comments

Comments

@jordwalke
Copy link

In SML, all functions take a single argument that may be a tuple (which gives us the standard f(x,y,z) notation).
Furthermore, if I recall correctly, all functions are actually pattern matching their tuple arguments such as:
fn 0 => 0
| n => 1

This seems like a really elegant way to model function parameters. Why does OPA not adopt this, and might is the community open to adopting the convention?

The parenthesis-free single argument syntax makes named parameters very elegant as well.

result = callFunction {
  param1: "someString",
  param2: 23
}
@akoprow
Copy link
Contributor

akoprow commented Feb 22, 2012

I assume you're referring to the new syntax of Opa (as we have two variants of the syntax). Quick explanation would be: this syntax is inspired and intended to stay close to JavaScript and that means parenthesis for function calls.

@akoprow akoprow closed this as completed Feb 22, 2012
@jordwalke
Copy link
Author

I was actually referring to the more concise syntax. I discussed this with you on the forum.
I was hopeful that the concise syntax could be a special case of what I propose (no parenthesis or commas needed for arguments).
For example:

someFunc 1 2 3

would call someFunc with three parameters, whereas:

anotherFunc (1,2,3)

calls anotherFunc with a single parameter that happens to be a tuple.

Here's the exact proposal I had on the web forum:

Before my proposal:

myComponent = MainApp({
   title = translate("welcome", "english")
   sideBar = SideBar({
      width = 400,
      onResize = (e) -> alert('hi')
   }),
   elements = [
        Link({siteSection = "a"})
   ]
})     // these double closings are very distracting.

After my proposal:

myComponent = MainApp {
   title: translate "welcome" "english",
   sideBar: SideBar {
      width:  400,
      onResize: (e) -> (alert 'hi')
   },
   elements = [
       Link { siteSection: "a" }
   ]
}

I felt this was clearly much cleaner.

I'll continue the discussion there.

@akoprow akoprow reopened this Feb 24, 2012
@hbbio
Copy link
Member

hbbio commented Apr 22, 2012

The syntax is nice, however we had enough recent focus on syntax to implement it now as:

  1. We want to keep the JavaScript default syntax as it is;
  2. We don't want to disturb the users of the original syntax who have lots of code already written.

But you can add your own syntax to Opa as the mechanism to select a given parser is already in the compiler.
PS: How would you write a type coercion?

@hbbio hbbio closed this as completed Apr 22, 2012
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

No branches or pull requests

3 participants