Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move examples to examples/ directory, add for loop example #64

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
File renamed without changes.
18 changes: 18 additions & 0 deletions examples/for.gr
Original file line number Diff line number Diff line change
@@ -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
})
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.