P.211 ~ 212 の部分再帰関数の実装。名前づけで混乱したので整理しなおしてみた。
# 部品1
def zero
0
end
# 部品2
def increment(n)
n + 1| import android.graphics.ImageFormat.NV21 | |
| import android.graphics.Rect | |
| import android.graphics.YuvImage | |
| import android.media.Image | |
| import java.io.ByteArrayOutputStream | |
| object Converter { | |
| fun jpegByteArrayFrom(yuv420_888: Image): ByteArray = | |
| yuv420_888.nv21ByteArray |
P.211 ~ 212 の部分再帰関数の実装。名前づけで混乱したので整理しなおしてみた。
# 部品1
def zero
0
end
# 部品2
def increment(n)
n + 1| fun <E> Collection<Collection<E>>.directProduct(): List<List<E>> = | |
| if (isEmpty()) { | |
| listOf() | |
| } else { | |
| val (head, rest) = first() to drop(1) | |
| head.map(::listOf).let { | |
| if (rest.isEmpty()) { | |
| it | |
| } else { | |
| rest.directProduct().flatMap { tail -> it.map { h -> h + tail } } |
| interface State | |
| interface Event | |
| data class Transition(val event: Event, val state State) | |
| val transitions: Map<State, Set<Transition>) = ... |
val mutex = java.util.concurrent.locks.ReentrantLock()
const val FULL = 2
var que = 0
fun prod() {
while (true) {
// P0: lock
mutex.lock()| package app | |
| fun main() { | |
| val rules: List<Rule> = listOf( | |
| object : Rule { | |
| override val name = "read" | |
| override fun applicable(shared: Shared, thread: Thread) = thread.ir == Location.P0 | |
| override fun convert(shared: Shared, thread: Thread) = shared to Local(Location.P1, shared.x) | |
| }, | |
| object : Rule { |
| object Executor { | |
| val uiExecutor = Handler(Looper.getMainLooper()).toExecutor() | |
| val ioExecutor = LooperThread().also { it.start() }.getHandler().toExecutor() | |
| private fun Handler.toExecutor(): Executor = Executor { | |
| while (!post(it)) { | |
| Thread.sleep(0) | |
| } | |
| } |
| const Z = f => (x => f(y => x(x)(y)))(x => f(y => x(x)(y))); | |
| const fact = Z(f => x => x != 0 ? x * f(x-1) : 1); | |
| fact(5); // => 120 |
| #include <cstdio> | |
| int main() { | |
| auto z = [](auto f) { | |
| auto g = [&f](auto x) { | |
| return f([&x](auto y) { return x(x)(y); }); | |
| }; | |
| return g(g); | |
| }; | |
| auto f = [](auto f) { |