Skip to content

Commit

Permalink
move examples to examples/ directory, add for loop examnple (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldemailly authored Jul 22, 2024
1 parent 1de9ad7 commit 68d0fcc
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 3 deletions.
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.

0 comments on commit 68d0fcc

Please sign in to comment.