Questions tagged [mutual-recursion]

Mutual recursion is a case in computer science where multiple problems that depend on each other form a cycle, like the chicken and egg problem.

104 questions
0
votes
1 answer

precedence climbing in haskell: parsec mutual recursion error

I'm programming the precedence climbing algorithm in Haskell, but for a reason unknown to me, does not work. I think that Parsec state info is lost at some point, but I don't even know that is the source of the error: module PrecedenceClimbing…
freinn
  • 1,049
  • 5
  • 14
  • 23
0
votes
1 answer

Comparing Two Mutually Recursive Values for Equality in HSpec is Causing Problems

1 The Context Consider the following snippet of Haskell: data T = T { f1 :: String , f2 :: T } deriving (Eq, Show) r1 = T { f1 = "val1" , f2 = r2 } :: T r2 = T { f1 = "val2" , f2 = r1 } ::…
George
  • 6,927
  • 4
  • 34
  • 67
0
votes
0 answers

Forward declaration on mutual recursion

I am rewriting a originally java program in c++, and I am having problems with two particular classes whose definitions depend on each other. After encountering the problem, I googled it and found out about forward declaration. I tried using it, but…
Michel
  • 133
  • 1
  • 8
0
votes
0 answers

Mutual Recursion to extract and sum an element of tuple

I've constructed a mutual-recursive type, consisting of more primitive types also defined like follows: type Title = Title of string;; type Value = Value of int;; type Subcol = Collection list and Collection = | Col of Title * Value * Subcol …
Syncretic
  • 75
  • 10
0
votes
2 answers

Mutually recursive functions in functional programming languages

A single recursive function can have tail recursion optimization applied to it, to prevent stack overflow, but what about mutually recursive functions? This answer shows how to define mutually recursive functions in F#: let rec F() = G() and…
ruben2020
  • 1,549
  • 14
  • 24
0
votes
2 answers

How to make mutually recursive structures in Javascript?

I was wondering if it is possible to have mutually recursive objects in Javascript and, if so, how? Goal: I want to have three objects: One that represents Boolean type with two values True and False One that represents a True object of Boolean…
Hassan Hayat
  • 1,056
  • 8
  • 20
0
votes
1 answer

Mutual recursion in racket, making cond do two things

I have two definitions, for a family tree and a person. ; a family-tree is: ; (make-person list-of-family-tree symbol number symbol) ; a person is: ; (define-struct person [children name date eyes]) I need to make a "mutually recursive"…
singmotor
  • 3,930
  • 12
  • 45
  • 79
0
votes
1 answer

How to call two functions and use their results as arguments for each other?

I have code: let join a ~with':b ~by:key = let rec a' = link a ~to':b' ~by:key and b' = link b ~to':a' ~by:(Key.opposite key) in a' and compilation result for it is: Error: This kind of expression is not allowed as right-hand side of …
Valentyn Zakharenko
  • 2,710
  • 1
  • 21
  • 47
0
votes
1 answer

Traverse nested Javascript arrays to create paths

I have an arbitrarily nested data structure like this - var nested = [ 'a', [ [ 'b' ], [ 'c' ] ] ]; I would like to traverse the levels to create an array of arrays like this var paths = [['a', 'b'] ['a', 'c']]; I know this is going to take…
-1
votes
1 answer

How to solve this indirect recursion error?

#include #include using namespace std; void funB(int n){ if (n>1){ cout<0){ cout<
-1
votes
1 answer

How to get the number of steps done in my mutual recursive program?

I'm new to OCaml. I have a little exercise for training to get familiar with the notion of mutual recursion in OCaml. The idea of the function I need to write is to be able to count the steps of the function Basically : there's a warehouse with 2…
TierTwo
  • 123
  • 2
  • 11
-1
votes
4 answers

mutually recursive functions

I am trying to understand why the below functions are outputting zero for any input I give them. I would have thought that based on the recursive nature that inputting a 2 to function g, would produce 12. Any integer I seem to use for either…
-1
votes
3 answers

Understanding the "Mutual Recursion Issue" for the Return Type of Functions

I know the problem of recursive definition of types in C++ for member variables: #include "B.h" class A { B b; }; #include "A.h" class B { A b; }; The compiler complains about this because it is not possible to allocate the memory in this…
awaelchli
  • 796
  • 7
  • 23
-2
votes
1 answer

How does this mutual recursion logic work?

The below code returns 39, and I can't understand how the logic works to where it arrives at 39. I keep getting 36 or 43. Can anyone list step by step how this program runs? a(1); function a(foo) { if(foo> 20) return foo; return b(foo+2); …
1 2 3 4 5 6
7