Skip to content

Commit

Permalink
Add a built-in template call test and make example in docs simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanhogg committed Jan 4, 2025
1 parent a2d54c9 commit 2bb6c2c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/language.md
Original file line number Diff line number Diff line change
Expand Up @@ -988,13 +988,13 @@ Similarly, template function calls can be used in functions to wrap a sequence
of expressions. For example:

```flitter
func onoise(seed, n, k, x, y, z)
func onoise(seed, n, k, x, y)
let weights=k**i for i in ..n
total=sum(weights)
@sum
for i in ..n
let scale=2**i
noise(seed, x*scale, y*scale, z*scale) * weights[i] / total
noise(seed, x*scale, y*scale) * weights[i] / total
```

This function is (almost) equivalent to the built-in function `octnoise()` and
Expand Down
14 changes: 14 additions & 0 deletions tests/test_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,20 @@ def test_template_calls(self):
!baz #test
""")

def test_template_builtin_calls(self):
self.assertCodeOutput(
"""
func foo(n)
@sum
for i in ..n
2**i
!foo foo=foo(10)
""",
"""
!foo foo=1023
""")

def test_nested_functions(self):
self.assertCodeOutput(
"""
Expand Down

0 comments on commit 2bb6c2c

Please sign in to comment.