-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding => for short lambda form. Bug fixes with incomplete maps. (#172)
* Adding => for short form of single param lambda. Fix bug with incomplete input not reported when using grol -c / string eval. review comment tweaks * review comment * Update eval/eval.go Co-authored-by: ccoVeille <[email protected]> * Update main_test.txtar Co-authored-by: ccoVeille <[email protected]> * Added => form of fib, added missing test file from previous PR * add comment to lexer * enforce for now the single ident on left of => * Update eval/memo_test.go * Added support for (a,b,..) => lambdas too * working with () => lambdas and multi too but format is failing, added failing tests, need extra () when printing * accept {} body and produce it in format so lambda can be called immediatly * add more test, make lambda work as map value * use lambda, remove a bunch of return * a few more use of => * convert anon functions to lambda form * Update token.go Co-authored-by: ccoVeille <[email protected]> * Update object/object.go --------- Co-authored-by: ccoVeille <[email protected]>
- Loading branch information
Showing
21 changed files
with
305 additions
and
101 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package eval_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"grol.io/grol/eval" | ||
"grol.io/grol/object" | ||
) | ||
|
||
func TestBigArrayNotHashable(t *testing.T) { | ||
// This test is to make sure that big arrays are showing as not hashable (so no crash when used later). | ||
oSlice := object.MakeObjectSlice(object.MaxSmallArray + 1) | ||
for i := range object.MaxSmallArray + 1 { | ||
oSlice = append(oSlice, object.Integer{Value: int64(i)}) | ||
} | ||
a := object.NewArray(oSlice) | ||
if _, ok := a.(object.BigArray); !ok { | ||
t.Fatalf("expected big array") | ||
} | ||
if object.Hashable(a) { | ||
t.Fatalf("expected big array to be not hashable") | ||
} | ||
m := object.NewMap() | ||
m = m.Set(object.Integer{Value: 1}, a) | ||
if object.Hashable(m) { | ||
t.Fatalf("expected map with big array inside to be not hashable") | ||
} | ||
c := eval.NewCache() | ||
c.Get("func(){}", []object.Object{a}) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/* Fibonacci using the lambda short form */ | ||
fib = x => if (x <= 1) {x} else {self(x - 1) + self(x - 2)} | ||
log("fib(35) =", fib(35)) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,2 @@ | ||
fact=func(n) { | ||
if (n<=1) { | ||
return 1 | ||
} | ||
n*fact(n-1) | ||
} | ||
fact = n => if (n<=1) {1} else {n*fact(n-1)} | ||
fact(50.) |
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
Oops, something went wrong.