diff --git a/Makefile b/Makefile index db601a87..559edfee 100644 --- a/Makefile +++ b/Makefile @@ -64,7 +64,7 @@ wasm/wasm_exec.html: test: grol CGO_ENABLED=0 go test -tags $(GO_BUILD_TAGS) ./... - ./grol *.gr + ./grol examples/*.gr generate: go generate ./... # if this fails go install golang.org/x/tools/cmd/stringer@latest diff --git a/README.md b/README.md index 42edd132..9b97ff60 100644 --- a/README.md +++ b/README.md @@ -54,11 +54,13 @@ print, log macros and more all the time -See also [sample.gr](sample.gr) that you can run with +See also [sample.gr](examples/sample.gr) and others in that folder, that you can run with ``` -gorepl *.gr +gorepl examples/*.gr ``` +or copypaste to the online version on [grol.io](https://grol.io) + ## Dev mode: ```shell go install golang.org/x/tools/cmd/stringer@latest diff --git a/apply.gr b/examples/apply.gr similarity index 100% rename from apply.gr rename to examples/apply.gr diff --git a/apply2.gr b/examples/apply2.gr similarity index 100% rename from apply2.gr rename to examples/apply2.gr diff --git a/examples/for.gr b/examples/for.gr new file mode 100644 index 00000000..9d304853 --- /dev/null +++ b/examples/for.gr @@ -0,0 +1,18 @@ +// for loop example, functional style +// executes with 1..n passed to the function parameter. + +for=func(n, f) { + l=func(i,f) { // internal lambda with the index param + r = f(i) + if (i>=n) { + return r + } + l(i+1, f) + } + l(1,f) +} + +for(5, func(n) { + log("n is", n) + n // return value at the end +}) diff --git a/large_fact.gr b/examples/large_fact.gr similarity index 100% rename from large_fact.gr rename to examples/large_fact.gr diff --git a/pi.gr b/examples/pi.gr similarity index 100% rename from pi.gr rename to examples/pi.gr diff --git a/pi2.gr b/examples/pi2.gr similarity index 100% rename from pi2.gr rename to examples/pi2.gr diff --git a/sample.gr b/examples/sample.gr similarity index 100% rename from sample.gr rename to examples/sample.gr