tail-call-optimization Questions

2

Solved

Lua claims that it implement tail call properly thus no stack needs to be maintained for each call thus allow infinite recursion, I tried to write a sum function, one is not tail call, and one is t...
Effie asked 9/11, 2012 at 6:44

3

Solved

I wrote the follwing function: let str2lst str = let rec f s acc = match s with | "" -> acc | _ -> f (s.Substring 1) (s.[0]::acc) f str [] How can I know if the F# compiler turned it ...
Mollee asked 30/4, 2009 at 12:44

2

Solved

Let's start with a straightforward definition of foldRight: def foldRight[T, U](base: U)(f: (T, => U) => U)(as: Seq[T]): U = { as match { case Nil => base case head +: next => f(head...
Latashalatashia asked 31/10, 2022 at 14:39

2

Solved

I've recently learned Haskell, and am trying to carry the pure functional style over to my other code when possible. An important aspect of this is treating all variables as immutable, i.e. constan...

4

Does the Go programming language, as of now, optimize tail calls? If not, does it at least optimize tail-recursive calls of a function to itself?
Mutual asked 24/8, 2012 at 3:5

7

Solved

I'm trying to write a program in functional style with C as much as possible. I know fine compilers like GCC/Clang do tail call optimization silently, but it's not guaranteed. Is there any option t...
Psychology asked 24/1, 2011 at 17:32

5

Solved

Two years after does-the-jvm-prevent-tail-call-optimizations, there seems to be a prototype implementation and MLVM has listed the feature as "proto 80%" for some time now. Is there no active inte...

2

Solved

How do I achieve stackless recursion in Java? The word that seems to come up the most is "trampolining", and I have no clue what that means. Could someone IN DETAIL explain how to achieve stackl...
Confluence asked 21/9, 2015 at 0:16

2

Solved

step_n(0, I, I). step_n(N, In, Out) :- N > 0, plus(N1, 1, N), phase_step(In, T), step_n(N1, T, Out). phase_step is a function that transforms data. Will this step_n run in almost the same mem...
Tideland asked 30/10, 2020 at 8:38

10

Solved

Very simply, what is tail-call optimization? More specifically, what are some small code snippets where it could be applied, and where not, with an explanation of why?

5

Solved

I am experimenting with a more functional style in my JavaScript; therefore, I have replaced for loops with utility functions such as map and reduce. However, I have not found a functional replacem...

5

Solved

Why won't the Scala compiler apply tail call optimization unless a method is final? For example, this: class C { @tailrec def fact(n: Int, result: Int): Int = if(n == 0) result else fact(n -...
Bremser asked 24/1, 2011 at 18:14

8

Solved

I often hear people say that C doesn't perform tail call elimination. Even though it's not guaranteed by the standard, isn't it performed in practice by any decent implementation anyhow? Assuming y...
Copperhead asked 18/8, 2010 at 16:24

1

Experimenting with tail call optimization (tco), I stumbled upon the following curious example: unsigned long long int fac1(unsigned long long int n){ if (n==0) return 1; return n*fac1(n-1); } ...
Percentage asked 25/10, 2017 at 11:51

1

Solved

I have this function that finds the even numbers in a list and returns a new list with only those numbers: def even([]), do: [] def even([head | tail]) when rem(head, 2) == 0 do [head | even(...
Victorvictoria asked 1/10, 2017 at 5:54

4

Solved

I like JavaScript so far, and decided to use Node.js as my engine partly because of this, which claims that Node.js offers TCO. However, when I try to run this (obviously tail-calling) code with No...
Lennon asked 24/4, 2014 at 5:17

1

Solved

We are using recursion to find factors and are receiving a StackOverflow exception. We've read that the C# compiler on x64 computers performs tail call optimizations: JIT definitely does tailcal...
Defelice asked 31/12, 2016 at 2:16

4

Solved

The following blog article shows how in F# foldBack can be made tail recursive using continuation passing style. In Scala this would mean that: def foldBack[T,U](l: List[T], acc: U)(f: (T, U) =&...
Sophistic asked 18/12, 2011 at 2:32

3

Solved

Some VMs, most notably the JVM, are said to not support TCO. As a result, language like Clojure require the user to use loop recur instead. However, I can rewrite self-tail calls to use a loop. Fo...
Genoa asked 19/4, 2014 at 20:57

1

Solved

The question Stack overflow despite tail call position but only in 64-bit lead to uncovering a bug in the F# compiler. After reading the answer I am curious as to the reasoning that lead to findi...
Capstan asked 4/3, 2016 at 14:54

1

Solved

For a parameter optimization problem at work I wrote a genetic algorithm to find some good settings because a brute-force solution is unfeasible. Unfortunately, when I return in the morning, most o...

3

Solved

In this talk, in the first 8 minutes, Runar explains that Scala has problems with tail call elimination, this makes me wonder whether F# has similar problems ? If not, why not ?
Coarctate asked 31/3, 2014 at 9:32

2

Solved

I'm having trouble finding the answer to this in the Clojure docs. I'm new to Clojure and it seems as though you can use recur in two different ways and essentially get the same result. Example 1:...
Birdiebirdlike asked 20/11, 2015 at 5:4

2

Solved

I'm experimenting with the foreign-function interface in Haskell. I wanted to implement a simple test to see if I could do mutual recursion. So, I created the following Haskell code: module Mutual...

2

Solved

I tried digging on the web to get my question answered. I found some documents related to Project DaVinci. This is tagged to the JSR 292 which is related to including closures in the JVM. Did this ...
Reckoner asked 4/4, 2014 at 15:9

© 2022 - 2024 — McMap. All rights reserved.