KittyCAD / kcl-experiments

KittyCAD Language
9 stars 0 forks source link

Unit tests and closures #1

Closed adamchalmers closed 1 year ago

adamchalmers commented 1 year ago

View the rendered markdown

I started designing unit tests and quickly realized we'll need closures to make unit tests ergonomic and easy to write. So, closures.

I think there should only be one syntax for declaring a function, whether it's named or anonymous. I like how Javascript lets you do this with const myFunc = (x) => {x+1}. We should take inspiration from that.

Ny new syntax for declaring a function is like this:

(params -> output-type) => expr

If you want to bind this function to a name, just do so!

myFunctionName = (params -> output-type) => expr

Both named and anonymous functions can have type annotations, or omit them and let the compiler infer them.