I hereby claim:
- I am Stupremee on github.
- I am stupremee (https://keybase.io/stupremee) on keybase.
- I have a public key whose fingerprint is 5AB7 076A F80B 4337 FB20 968C D54A 1CD5 1376 F46C
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
CC := cc | |
CCFLAGS := -fdiagnostics-color=always -Wall -Werror -Wextra | |
CCOBJFLAGS := $(CCFLAGS) -c | |
BIN_PATH := bin | |
OBJ_PATH := obj | |
SRC_PATH := src | |
TARGET_NAME := chat | |
TARGET := $(BIN_PATH)/$(TARGET_NAME) |
#include "testlib.h" | |
#include <stdlib.h> | |
#include <stddef.h> | |
#include <inttypes.h> | |
typedef struct vec { | |
void **data; | |
uint32_t len; | |
uint32_t cap; | |
} vec; |
// The source code for `/tmp/crab` which is used to test the code. | |
use std::thread; | |
use std::time::Duration; | |
fn main() { | |
let t1 = thread::spawn(|| { | |
println!("[1] Thread started working"); | |
thread::sleep(Durtaion::from_millis(5000)); | |
println!("[1] Thread finished working"); | |
}; |
@Dannie well yes but actually no. The problem is still that when the body of a lambda is executed, a stack frame is allocated. The point of trampoling is to not do that
essentially you have some run
method of Trampoline which is iterative or tail recursive and by suspending all of your functions in that Trampoline type (rather than executing them in place), you can make the execution of the original function only take one stack frame
it's all very roundabout
and actaully something I didnt really think about is that you can manually write run
to be iterative, not relying on there being tail call optimization. That means it's possible in java as well @tterrag
yeah here we go
interface Trampoline<T> {
default T run() {
import java.util.Arrays; | |
public class QuickSort { | |
public int[] sort(int[] array) { | |
return Arrays.stream(sort(Arrays.stream(array).boxed().toArray(Integer[]::new))) | |
.mapToInt(Integer::intValue) | |
.toArray(); | |
} |