Skip to content

Commit

Permalink
Merge pull request #806 from summivox/bound-optr-fn
Browse files Browse the repository at this point in the history
fixes #634 : Partial application should be bound (like bound functions)
  • Loading branch information
vendethiel committed Feb 1, 2016
2 parents 9127329 + 177bf88 commit 9bdd5df
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/ast.ls
Original file line number Diff line number Diff line change
Expand Up @@ -1469,9 +1469,9 @@ class exports.Binary extends Node
y = Var \y$
sn(this, (Fun [x, y], Block((Binary @op, x, y).invert-check this), false, true).compile o)
case @first?
sn(this, "(", ((Fun [vit], Block((Binary @op, @first, vit) .invert-check this)).compile o), ")")
sn(this, "(", ((Fun [vit], Block((Binary @op, @first, vit) .invert-check this), true).compile o), ")")
default
sn(this, "(", ((Fun [vit], Block((Binary @op, vit, @second).invert-check this)).compile o), ")")
sn(this, "(", ((Fun [vit], Block((Binary @op, vit, @second).invert-check this), true).compile o), ")")

compileRegexEquals: (o, [regex, target]) ->
if @op is \===
Expand Down
4 changes: 2 additions & 2 deletions src/lexer.ls
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ character = if not JSON? then uxxxx else ->
tokens.splice i, 0,
* 'PARAM(' '(' line, column
* ')PARAM' ')' line, column
* '->' '->' line, column
* '->' '~>' line, column
* 'ID' 'it' line, column
else if next.0 is ')'
tokens.splice i + 1, 0,
Expand All @@ -1020,7 +1020,7 @@ character = if not JSON? then uxxxx else ->
['PARAM(' '(' line, column]
['ID' 'it' line, column]
[')PARAM' ')' line, column]
['->' '->' line, column]
['->' '~>' line, column]
break LOOP
prev = token
continue
Expand Down
13 changes: 13 additions & 0 deletions test/operator.ls
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,19 @@ eq '1,2,3,4' String (++) a, [3 4]
eq '3,4,1,2' String (++ a) [3 4]
eq '1,2,3,4' String (a ++) [3 4]

# partially bound binary operators should also bind `this`
# see [#634](https://github.com/gkz/LiveScript/issues/634)
o =
x: 1
y: 2
f: ->
ok (@x ==)(1)
ok (== @x)(1)
eq 2 (+ @x)(1)
(@y =)(3)
eq 3, @y
o.f!

# Unary ops as functions
ok (not) false
ok (!).call(null, false)
Expand Down

0 comments on commit 9bdd5df

Please sign in to comment.