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.
Questions tagged [mutual-recursion]
104 questions
1
vote
1 answer
F#: To Design or not design with mutually dependably record types
I try to model trees with their nodes using F# records.
Here is an abstraction of what my design looks like:
type Tree = { Root: Node }
and Node = { Tree: Tree }
(There are other record fields, of course.)
The rationale is that given a tree I…

7enderhead
- 71
- 4
1
vote
2 answers
Impossible to delete in Django Admin — object refers to ITSELF as a protected object
In Django Admin, I have a model called Modules.
When I try to delete a Module object, I get the following error:
Deleting the module 'FR menu' would require deleting
the following protected related objects:
Module: FR menu
I understand why this…

Andy Swift
- 2,179
- 3
- 32
- 53
1
vote
1 answer
Expression for defining letrec implementing little language in Haskell
I'm writing an evaluator for a little expression language, but I'm stuck on the LetRec construct.
This is the language:
data Expr = Var Nm | Lam (Nm,Ty) Expr | App Expr Expr
| Val Int | Add Expr Expr | If Expr Expr Expr
| Let Nm Expr…

whoareu
- 63
- 7
1
vote
1 answer
ANTLR4 self and mutual left-recursion
Is there a simple transformation or workaround to make this work in ANTLR4?
a : a p
| b q
| c
;
b : b r
| a s
| d
;
That is, a and b are self-left-recursive and mutual-left-recursive, the other rules (c, d, p, q, r, s) are just…

TFuto
- 1,361
- 15
- 33
1
vote
3 answers
Can anyone explain this output to me?
So I was playing around with some thought experiments where I imagined what would happen when two functions became mutually recursive. One such one was what if both functions could potentially fall into an infinite loop.
To that end, I thought up of…

Mike Bailey
- 12,479
- 14
- 66
- 123
1
vote
1 answer
How do you find if a file is within a directory tree using scheme?
I'm trying to write a function find which consumes a directory tree and a file name and determines whether or not a file with that name occurs in the directory tree. What i've written work with files within the first level of the tree (read!), but…

Dave
- 11
- 1
1
vote
3 answers
Program returns a value of -1073741571 instead of going forever
i'm learning about functions and decided to make a loop where two function(in this case funcA and funcB ) call each other forever but it stops execution after some time.
The code looks like this:
#include
void funcA(); //forward…

SgerS1
- 131
- 5
1
vote
2 answers
How to achieve mutual recursion to avoid names not being defined?
I've a clojure program in which two function recursively call each other:
(defn f1
...
(f2 ...)
)
(defn f2
...
(f1 ...)
)
The compiler is giving an error in f1. It's saying that f2 isn't defined. Is there a way to declare a function in clojure. I…

saga
- 1,933
- 2
- 17
- 44
1
vote
2 answers
Tell if number is odd or even with SML
This is the second SML program I have been working on. These functions are mutually recursive. If I call odd(1) I should get true and even(1) I should get false. These functions should work for all positive integers. However, when I run this…

Michael Drum
- 1,151
- 5
- 14
- 26
1
vote
2 answers
Coq: defining more than two mutually recursive functions on inductive type
I am defining three mutually recursive functions on inductive type event, using two different ways: using with and fix keywords, however, Coq complains about principal argument and The reference ... was not found in ..., respectively.
Two…

Khan
- 303
- 2
- 14
1
vote
1 answer
Split huge F# file with mutually recursive functions
In F# I have a very long code file like
let rec f1 a1 a2 a3 a4 a5 .. aN =
...
and f2 a1 a2 a3 a4 a5 ... aN =
...
and f3 a1 a2 a3 a4 a5 ... aN =
...
and f40 a1 a2 a3 a4 a5 ... aN =
…

seguso
- 2,024
- 2
- 18
- 20
1
vote
1 answer
How can I write this function only by using recursion in F#?
let rec n_cartesian_product = function
| [] -> [[]]
| x :: xs ->
let rest = n_cartesian_product xs
List.concat (List.map (fun i -> List.map (fun rs -> i :: rs) rest) x)
Hello! I wrote this function but I need to write it…

Anton Maria Prati
- 181
- 11
1
vote
1 answer
Convert two mutually recursive methods into single recursive method in java?
I need to take a program with two mutually recursive methods and modify the program so that it contains a single recursive method. From what i understand, I need to combine the two recursive methods by placing the recursive calls in a single method…

Shwig
- 55
- 6
1
vote
2 answers
Avoid cyclic dependencies - need for mutual containment
In my GUI system, the main building block is Container class, which can be drawn (= is drawable). However, Container itself is a 'kind of a table' - it contains cells.
Cell class serves for layouting. The number of cells a container has is defined…

sjaustirni
- 3,056
- 7
- 32
- 50
1
vote
1 answer
Prolog Mutual recursion
Ok I'm writing some code to go through a check each value by mutual recursion in Prolog.
This is my code so far:
semestersok(SP) :-
[Prior|Tail] = SP,
sem1ok(SP).
%% sem1ok(SP) :- checks semester 1 of SP is ok
sem1ok(SP) :-
…

Aaron Troeger
- 165
- 1
- 5
- 18