Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format function definition with arguments on multiple lines?

Tags:

coffeescript

I'd like to put arguments on different lines, but I get parse errors on all the variations I try, including adding commas, allwin-style parens, and different indentations.

  constructor: (
    @a
    @b
    @c
  ) ->
like image 893
Loren Avatar asked Oct 20 '11 23:10

Loren


People also ask

Does the order of arguments in a function matter?

Yes, it matters. The arguments must be given in the order the function expects them. C passes arguments by value. It has no way of associating a value with an argument other than by position.

How many written argument can be there in the function?

Except for functions with variable-length argument lists, the number of arguments in a function call must be the same as the number of parameters in the function definition. This number can be zero. The maximum number of arguments (and corresponding parameters) is 253 for a single function.

What is function argument explain with example?

Information can be passed into functions as arguments. Arguments are specified after the function name, inside the parentheses. You can add as many arguments as you want, just separate them with a comma. The following example has a function with one argument (fname).


2 Answers

Try:

constructor:\
( @a
, @b
, @c
) ->

Both trailing \ and leading , suppress newlines in CoffeeScript.

like image 167
matyr Avatar answered Sep 24 '22 14:09

matyr


It appears you are out of luck. If you look at the grammar rules for the function definition, you will see that the rule is defined as:

'PARAM_START ParamList PARAM_END FuncGlyph Block'

The rule for Block allows for TERMINATOR tokens (which are semi-colon or carriage return) but the ParamList rule (the one you are interested in adding a new line in) does not allow for it.

like image 22
Brian Genisio Avatar answered Sep 24 '22 14:09

Brian Genisio