-
Notifications
You must be signed in to change notification settings - Fork 863
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(fix) Throw exception when assignment to captured variables, issue #101
- Loading branch information
1 parent
5e53bcd
commit afc9c46
Showing
6 changed files
with
57 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 14 additions & 1 deletion
15
src/test/java/com/googlecode/aviator/example/LambdaExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,27 @@ | ||
package com.googlecode.aviator.example; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import com.googlecode.aviator.AviatorEvaluator; | ||
|
||
public class LambdaExample { | ||
|
||
public static void main(String[] args) { | ||
|
||
String exp = "a=1; b = lambda(x) -> a+ x end ; a=4 ; b(5)"; | ||
String exp = "a=1; b = lambda(x) -> a+ x end ; b(5)"; | ||
System.out.println(AviatorEvaluator.execute(exp)); // output 6 | ||
|
||
|
||
Map<String, Object> env = new HashMap<String, Object>(); | ||
env.put("x", 1); | ||
env.put("y", 2); | ||
env.put("z", 3); | ||
|
||
AviatorEvaluator.defineFunction("test", | ||
"lambda(x) -> lambda(y) -> lambda(z) -> x + y + z end end end"); | ||
System.out.println(AviatorEvaluator.execute("test(4)(5)(6)", env)); // output 15 | ||
|
||
env.put("a", 4); | ||
System.out.println(AviatorEvaluator.execute("test(4)(5)(6) + a", env)); // output 19 | ||
} | ||
} |