34 lines
769 B
Plaintext
34 lines
769 B
Plaintext
& Lesson 10: ngons
|
|
|
|
& Recall our first function:
|
|
fn simple_box! () -> { fd! (100); rt! (0.25) }
|
|
|
|
& Recall our second function:
|
|
fn box! (size) -> { fd! (size); rt! (0.25) }
|
|
|
|
& What haven't we "parameterized" yet?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn ngon! (n, size) -> repeat n { fd! (size); rt! (div (1, n)) }
|
|
& ^ ^^^^^^^^^^
|
|
& Note n: what does this represent?
|
|
& What does `div (1, n)` mean here?
|
|
& Why is it here?
|
|
& Note: we could also have used `inv (n)`--inverse is 1/x
|
|
& What other math can we do?
|
|
& cf. https://alea.ludus.dev/twc/ludus/src/branch/main/prelude.md#math
|
|
& What happens when you pass in strange values? 0? 1? 2?
|
|
& Note `div` does not end in a bang.
|
|
& This differentiates between functions with side effects vs. return values.
|