DreamBerd icon indicating copy to clipboard operation
DreamBerd copied to clipboard

Implement support for pure fun and Universe type

Open LiberaVeritas opened this issue 1 year ago • 1 comments

Pure Fun

New for 2023!
Impure functions are an anti-pattern. Use the pure keyword to make a function pure. Pure functions never have side-effects, and return the same output given the same input.

pure fun twice(x) => 2 * x!

To do anything useful with pure functions like having side-effects or changing state, DreamBerd features the Universe type. You can write a pure function to simply take the entire universe and input, and return a new universe with the changes you want.

pure fun withCompiler(universe) => {
   return universe where {compiler = exists}!
}

This solves the issue with the current DreamBerd compiler not working, except the fact that a compiler is required to compile withCompiler in the first place.

You can easily make any function pure, since pure is pure syntax sugar. Any impure behavior automatically wrapped in a pure context which injects the current universe and returns a new one.

pure fun hello() => print("Hello")!  // perfectly pure

Please take care when using delete with Universe objects.

LiberaVeritas avatar Jun 07 '23 23:06 LiberaVeritas

actually not sure where the best location in the readme to put this would be

LiberaVeritas avatar Jun 14 '23 14:06 LiberaVeritas