gkz / LiveScript

LiveScript is a language which compiles to JavaScript. It has a straightforward mapping to JavaScript and allows you to write expressive code devoid of repetitive boilerplate. While LiveScript adds many features to assist in functional style programming, it also has many improvements for object oriented and imperative programming.
http://livescript.net
MIT License
2.32k stars 155 forks source link

bracket spacing threw unexpected error in function invocation #1058

Closed sourcevault closed 6 years ago

sourcevault commented 6 years ago

a = 1
b = 2

f = (x,y) -> x + y

f (a,b) # throws error :(

I was quite surprised that this caused parse error :|

Function {
  message: 'Parse error on line 1: Unexpected \',\'',
  hash:
   { text: undefined,
     token: ',',
     line: 0,
     loc: { first_line: 0, first_column: 3, last_line: 0, last_column: 4 },
     expected:
      [ '\'BIOP\'',
        '\')\'',
        '\'BIOPR\'',
        '\'BACKTICK\'',
        '\'NEWLINE\'',
        '\'INDENT\'',
        '\'IMPORT\'',
        '\'+-\'',
        '\'COMPARE\'',
        '\'LOGIC\'',
        '\'MATH\'',
        '\'POWER\'',
        '\'SHIFT\'',
        '\'BITWISE\'',
        '\'CONCAT\'',
        '\'COMPOSE\'',
        '\'RELATION\'',
        '\'PIPE\'',
        '\'BACKPIPE\'',
        '\'POST_IF\'' ] } }
vendethiel commented 6 years ago

That's correct. This is an error. LiveScript has no tuples.

sourcevault commented 6 years ago

I am trying to do a normal function call like so :


f a,b # no error 
rhendric commented 6 years ago

Welcome to LiveScript! It's true, f (a, b) is not valid and is not intended to be so. LiveScript is a very whitespace-sensitive language. For example, there is a big difference between a[b, c] and a [b, c]—the former will compile to [a[b], a[c]], while the latter will compile to a([b, c]). By analogy, f (a, b) would mean to apply f to whatever (a, b) means, but as ven observes, the expression (a, b) doesn't mean anything in LiveScript, so this is an error, whereas f(a, b) is valid (as is f a, b, as you observe).