You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`Function::apply` returns the result for the given arguments.
77
85
```
78
-
val plusTwo = Successor().andThen(Successor())
86
+
val plusTwo = Successor()andThenSuccessor()
79
87
println(plusTwo.apply(0)) //prints 2
80
88
println(plusTwo.apply(40)) //prints 42
81
89
```
82
-
Projectionand Successor are evaluated lazily, meaning only the required argument is evaluated.\
83
-
By default, Composition and and Recursion are not lazy. However, both can be set to evaluate lazily as well.
90
+
Projection, Successor, Recursion and composition with andThen are evaluated lazily, meaning only the required arguments are evaluated.\
91
+
In order to avoid StackOverflowErrors, Composition is not lazy. However, compositions (with the exception of infix compositions) can be set to evaluate lazily as well.
84
92
```
85
93
val myLazyComposition = Composition(myEvaluator, myFunctions, lazy = true)
val myLazyRecursion = Recursion(myBaseCaseFunction, myRecursiveCaseFunction, lazy = true)
89
95
```
90
-
Additional examples and various macros can be found [here](src/main/kotlin/eu/yeger/prf/Functions.kt).\
91
-
Non-recursive [implementations](src/main/kotlin/eu/yeger/prf/non_recursive/NonRecursiveFunctions.kt) of all macros are included as well.\
92
-
They are interchangeable with the recursive implementations and provide improved performance (and less StackOverflowErrors).
96
+
Additional examples and various macros can be found [here](src/main/kotlin/eu/yeger/refunk/recursive/RecursiveFunctions.kt).\
97
+
Non-recursive [implementations](src/main/kotlin/eu/yeger/refunk/non_recursive/NonRecursiveFunctions.kt) of all macros are included as well.\
98
+
They are interchangeable with the recursive implementations and provide improved performance (and less StackOverflowErrors).\
99
+
Using the non-recursive implementations of macros is highly recommended.
93
100
94
-
## Exceptions
101
+
## Exceptions and error handling
95
102
96
103
- Evaluating a function will throw an `ArityException` if not enough arguments were passed.
97
104
- Setting the arity of a function to a negative value will throw an `ArityException`.
98
105
- Projecting a negative index will throw a `ProjectionException`.
99
-
- Composing functions will throw a `CompositionException` if the arity of the evaluating function is not met.
100
-
- Composing with `andThen` will throw a `CompositionException` if the parameter is not an unary function.
101
-
- Negative values will, at any point during the evaluation and instantiation, throw a `NaturalNumberException`.
102
-
- Evaluating a `Successor` function will throw a `NaturalNumberException` if it would cause an overflow. **Note**: None of the non-recursive macros will throw an exception in this case, and instead set the value to 0.
106
+
- Composing functions will throw a `CompositionException` if the arity of the evaluating function and the number of provided functions do not match.
107
+
- Applying or creating constants with negative values will throw a `NaturalNumberException`.
108
+
- Any provided method will throw an `OverflowException` if an overflow occurs during evaluation.
103
109
104
-
## Intention
110
+
## Disclaimer
105
111
106
-
This library is intended as a tool for studying primitive recursive functions, since evaluating them by hand can be quite tedious.\
112
+
This library is intended as a tool for studying primitive recursive functions.\
107
113
Because the implementation is based on experimental Kotlin features, using them in production is not recommended.
0 commit comments