Questions tagged [trampolines]

A technique to emulate (or augment) jumps / function calls by a custom dispatch. A single trampoline is sufficient to express all control transfers of a program.

A technique to emulate (or augment) jumps / function calls by a custom dispatch to converted functions which return control back to the dispatch (a.k.a. the trampoline) instead of making the function calls themselves, using data to control the control flow.

A single trampoline is sufficient to express all control transfers of a program; a program so expressed is trampolined or in "trampolined style"; converting a program to trampolined style is trampolining. Trampolined functions can be used to implement tail recursive function calls in stack-oriented languages.

See Wikipedia.

71 questions
0
votes
1 answer

Trampoline based linked list (lisp tree) to string with cycles

I have problem with my trampoline based function that stringify lisp list. Here is the code: function Pair(car, cdr) { this.car = car; this.cdr = cdr; } const nil = new function Nil() {}; //…
jcubic
  • 61,973
  • 54
  • 229
  • 402
0
votes
3 answers

Using trampoline to create tree from nested arrays and covert that to string

I want to rewrite all recursive function in my lisp in JavaScript with trampoline. I have two examples I don't know how to rewrite: Pair.fromArray = trampoline(function fromArray(array) { if (array.length === 0) { return nil; } else…
jcubic
  • 61,973
  • 54
  • 229
  • 402
0
votes
3 answers

LeetCode #70 Climbing Stairs, How to speed up my solution?

I have a solution to this problem on LeetCode #70 Climbing stairs, My solution is not passing, due to it being slow... I have added a trampoline utilizing thunks and I've added Memoization, what else can I add to speed this up to actually pass the…
0
votes
1 answer

using a trampoline with one function as an argument

I know what a trampoline function is, but I've been having trouble avoiding stack overflow using trampolines. So far, the only method I can think of is to use global variables, which are discouraged and can complicate programs. The trampoline…
gt453
  • 13
  • 2
0
votes
1 answer

Avoiding stack overflow using a trampoline

The trampoline function in the program below works properly. I think the program below results in stack overflow because the functions thunk_f and thunk1 call each other indefinitely, resulting in the creation of new stack frames. However, I want to…
user13321389
0
votes
1 answer

Trampoline recursion causes "Maximum call stack size exceeded"

I am studying blockchain and I am implementing a really simple "proof of work". Proof of work: export function mineBlock(difficulty: number, block) { const prefix = Array(difficulty + 1).join("0"); function mine(block, difficulty) { const…
0
votes
0 answers

how to calculate the correct size to copy into the trampoline

I'm trying to hook functions in x64 bit windows I can hook the target function easily but the problem is in creating the trampoline I need to know a suitable size to copy from the original function to the trampoline and then coping the jmp…
dev54312
  • 53
  • 3
0
votes
1 answer

Export Function needs to be set as a pure function

In the below piece of Trampoline code, I will be calling onclick = export(add,5) from my button present in my view. How do I ensure that this call always returns the value of 5 without uncommenting the line where //x=0 in the code below? var x =…
vamsee
  • 31
  • 1
  • 9
0
votes
1 answer

Proper terminology for replacing myValue with myValue()

I keep seeing this pattern of value replacement, and I'm trying to figure out how I can explain the substitution to my coworkers. Question What are the proper, definitive words for: this substitution the substituted function In many…
neaumusic
  • 10,027
  • 9
  • 55
  • 83
0
votes
2 answers

Coding static to instance method trampoline function with templates

I'm trying to recode some rather ugly template coding. For reference, the original is here: https://codereview.stackexchange.com/questions/69545/recode-c-c-trampoline-function-macros-using-templates class Final : Base { void Foo(){...} void…
P i
  • 29,020
  • 36
  • 159
  • 267
0
votes
1 answer

Understanding how to convert recursive to a trampoline

I've recently read about trampolining as a way to eliminate tail calls. I'd like to convert one of my functions to something that utilizes trampolines, but I'm having a tough time getting going (I'm coming here from the OO world). def buildTree…
dave
  • 12,406
  • 10
  • 42
  • 59
1 2 3 4
5