Skip to content

Commit b1d7347

Browse files
authored
Merge pull request #15 from DerYeger/release/v2.0.0
Release/v2.0.0
2 parents 992a743 + 031d2ac commit b1d7347

40 files changed

+790
-777
lines changed

.idea/.name

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
# Primitive Recursive Functions
1+
# Refunk
22

33
> Primitive recursive functions made simple with Kotlin
44
55
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
6-
[![Release](https://jitpack.io/v/DerYeger/primitive-recursive-functions.svg)](https://jitpack.io/#DerYeger/primitive-recursive-functions)
6+
[![Release](https://jitpack.io/v/DerYeger/refunk.svg)](https://jitpack.io/#DerYeger/refunk)
77

88
A small and lightweight library for studying and evaluating primitive recursive functions in Kotlin.
99

@@ -21,7 +21,7 @@ allprojects {
2121
```
2222
```
2323
dependencies {
24-
implementation 'com.github.DerYeger:primitive-recursive-functions:v1.1.0'
24+
implementation 'com.github.DerYeger:refunk:v2.0.0'
2525
}
2626
```
2727

@@ -38,70 +38,76 @@ dependencies {
3838
```
3939
<dependency>
4040
<groupId>com.github.DerYeger</groupId>
41-
<artifactId>primitive-recursive-functions</artifactId>
42-
<version>v1.1.0</version>
41+
<artifactId>refunk</artifactId>
42+
<version>v2.0.0</version>
4343
</dependency>
4444
```
4545

4646
## Usage
4747

4848
### Basic functions
4949

50-
- `val c = Constant(value)`
50+
- `val c = Constant(value)` with macros `c(value)`, `zero()` and `one()`.
5151
- `val s = Successor()`
52-
- `val p = Projection(index)`
53-
- `val myRecursion = Recursion(myBaseCaseFunction, myRecursiveCaseFunction)`
52+
- `val p = Projection(index)` with macros `p(index)`, `first()`, `second()` and `third()`.
5453

5554
### Composition
5655

57-
Composed functions like `(args) -> f(g1(args), ..., gn(args))` can be created with the `Composition` class
56+
Composed functions like `(args) -> f(g1(args), ..., gn(args))` can be created with the `Composition` class and various extension methods.
5857
```
5958
val f = ...
6059
val g1 = ...
6160
...
6261
val gn = ...
63-
val myComposition = Composition(f, g1, ..., gn)
64-
```
65-
or by using `Function::compose`.
66-
```
67-
val myComposition = f.compose(g1, ..., gn)
62+
val myExplicitComposition = Composition(f, g1, ..., gn)
63+
val myMethodComposition = f.compose(g1, ..., gn)
64+
val myInfixComposition = f of { g1 and ... and gn }
6865
```
6966
Unary functions can also be composed by using `Function::andThen`
7067
```
7168
val myComposition = myFunction.andThen(myUnaryFunction)
69+
val myInfixComposition = myFunction andThen myUnaryFunction
70+
```
71+
72+
### Recursion
73+
74+
Recursions can also be created using multiple extension methods.
75+
76+
```
77+
val myClassicRecursion = Recursion(myBaseCaseFunction, myRecursiveCaseFunction)
78+
... = recursive(myRecursiveCaseFunction) withBaseCase myBaseCaseFunction
79+
... = recursive { myRecursiveCaseFunction of myHelperFunction } withBaseCase { someFunction andThen someOtherFunction }
7280
```
7381

7482
### Evaluation
7583

7684
`Function::apply` returns the result for the given arguments.
7785
```
78-
val plusTwo = Successor().andThen(Successor())
86+
val plusTwo = Successor() andThen Successor()
7987
println(plusTwo.apply(0)) //prints 2
8088
println(plusTwo.apply(40)) //prints 42
8189
```
82-
Projection and 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.
8492
```
8593
val myLazyComposition = Composition(myEvaluator, myFunctions, lazy = true)
8694
... = myEvaluator.compose(myFunctions, lazy = true)
87-
... = myFunction.andThen(myUnaryFunction, lazy = true)
88-
val myLazyRecursion = Recursion(myBaseCaseFunction, myRecursiveCaseFunction, lazy = true)
8995
```
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.
93100

94-
## Exceptions
101+
## Exceptions and error handling
95102

96103
- Evaluating a function will throw an `ArityException` if not enough arguments were passed.
97104
- Setting the arity of a function to a negative value will throw an `ArityException`.
98105
- 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.
103109

104-
## Intention
110+
## Disclaimer
105111

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.\
107113
Because the implementation is based on experimental Kotlin features, using them in production is not recommended.

build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
plugins {
2-
id 'org.jetbrains.kotlin.jvm' version '1.3.50'
2+
id "org.jetbrains.kotlin.jvm" version "1.3.50"
33
}
44

5-
group 'eu.yeger'
6-
version '1.1.0'
5+
group "eu.yeger"
6+
version "v2.0.0"
77

88
repositories {
99
mavenCentral()
1010
}
1111

1212
dependencies {
13-
testCompile "junit:junit:4.12"
14-
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
13+
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
14+
testImplementation("junit:junit:4.12")
1515
}
1616

1717
compileKotlin {
18-
kotlinOptions.jvmTarget = "1.8"
1918
kotlinOptions {
2019
freeCompilerArgs = ["-XXLanguage:+InlineClasses"]
20+
jvmTarget = "1.8"
2121
}
2222
}
2323

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
rootProject.name = 'prf'
1+
rootProject.name = 'refunk'
22

src/main/kotlin/eu/yeger/prf/Argument.kt

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/main/kotlin/eu/yeger/prf/Function.kt

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)