Skip to content

Indentation while defining function arguments #1355

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

Closed
marek-kuzora opened this issue May 12, 2011 · 5 comments
Closed

Indentation while defining function arguments #1355

marek-kuzora opened this issue May 12, 2011 · 5 comments

Comments

@marek-kuzora
Copy link

# First example
fn '1'
  attr: 'v1'

  fn '2'
    attr: 'v2'

    fn '3'

# Second example
fn '1'
  attr: 'v1'

  fn '2'
    fn '3'

# Third example
fn '1'
  attr: 'v1'

  fn '2',
    fn '3'

Compiles into

  fn('1', {
    attr: 'v1'
  }, fn('2', {
    attr: 'v2'
  }, fn('3')));

  fn('1', {
    attr: 'v1'
  }, fn('2'), fn('3'));

  fn('1', {
    attr: 'v1'
  }, fn('2', fn('3')));

Is there any chance that the "," from the third example could be omitted as it is in the first example and still return expected result based on the indentation?

@TrevorBurnham
Copy link
Collaborator

I think Jeremy is pretty set against code like

fn '2'
  fn '3'

Semantic indentation for logical structures is one thing; for grouping function arguments, it's another.

Mind you, it's certainly weird that a comma does that... but it's not clear to me (or the compiler) what you intended the indentation to do.

@satyr
Copy link
Collaborator

satyr commented May 12, 2011

What about

if fn '2'
  fn '3'

?

@TrevorBurnham
Copy link
Collaborator

Right. As I said:

Semantic indentation for logical structures is one thing; for grouping function arguments, it's another.

if falls into the first category. The current compilation

if (fn('2')) {
  fn('3');
}

is eminently sensible, unless we want to completely rethink how implicit parentheses work.

@marek-kuzora
Copy link
Author

I agree with 'if' example. There is no way to know it the fn '3' is an argument of fn '2' or in if clausule. But my question was if there is possibility of omitting the comma when the compiler already knows that we are defining arguments as in example:

fn '1'
  attr: 'v1'

  fn '2',
    fn '3'

Here, if I omitt the comma the whole expression won't be ambiguous for the compiler because I knows that we are already defining arguments for fn '1'. Currently ommiting comma results into adding fn '3' as an argument for fn '1' instead of fn '2'

@jashkenas
Copy link
Owner

Yep, Trevor's got this one right -- this is a road we really don't want to be going down. The only meaningful significant indentation/call is this one:

configure
  name: "input"
  preload: "images"

... because it's just sugar for:

configure {
  name: "input"
  preload: "images"
}

Other types of indentation-means-arguments have been proposed before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants