Questions tagged [anonymous-recursion]

Anonymous-recursion is recursion which does not explicitly call a function by name. This is usually done by calling the current function from within itself or by passing the current function as a callback to an other (named) function. Use this tag for questions directly related to this type of recursion only.

6
votes
7answers
248 views

Which programming languages support functions that take themselves as arguments?

I'm doing an academic exercise (for personal growth). I want to find programming languages that allow you to define functions that are capable of accepting themselves (i.e., pointers to themselves) as ...
2
votes
2answers
146 views

Little Schemer: why wrap (mk-length mk-length) into a function?

In The Little Schemer book, in Chapter 9, while building a length function for arbitrary long input, the following is suggested (on pages 170-171), that in the following code snippet (from page 168 ...
0
votes
1answer
72 views

How to create a big array of Func's representing a Vandermonde system in C#?

I am trying to create a big Vandermonde array of Func's. I can create a 4x3 system like this: Func<double[], double>[] vandermondeSystem = { x => x[0]*Math.Pow(1, 0) + x[1]*Math.Pow(1, ...
3
votes
2answers
170 views

Little Schemer: write function that only supports lists of length ≤ 2

In the book The little schemer, we find this function that only supports lists with length smaller than or equal to 1: (((lambda (mk-length) ; A. (mk-length mk-...
5
votes
2answers
558 views

The mechanism of anonymous function to call itself in Scheme?

I'm reading The Little Schemer and feel confused about the following code: ((lambda (len) (lambda (l) (cond ((null? l) 0) (else (+ 1 (len (cdr l))))))) ...
6
votes
1answer
405 views

Two-layer “Y-style” combinator. Is this common? Does this have an official name?

I've been looking into how languages that forbid use-before-def and don't have mutable cells (no set! or setq) can nonetheless provide recursion. I of course ran across the (famous? infamous?) Y ...
2
votes
1answer
235 views

How to do this length≤1 more than once?

I've spent a day reading page 166's length≤1 in the book The Little Schemer; there's the following code: (((lambda (mk-length) (mk-length mk-length)) (lambda (mk-length) (lambda (l) (...
0
votes
2answers
1k views

Recursion function failed in CodeIgniter

I am using a recursion function to convert my menus in a tree. The array I got from the database is: array ( [0] => stdClass Object ( [nav_group_id] => 1 [entity_id] => 1 [...
1
vote
1answer
332 views

C# anonymous recursion and Y-combinator performance

Below are are functions and tests of anonymous recursion. The first one is true Y-combinator, looks fine and simple, but is quite slow. It takes 1000ms to execute 1 mln iterations. The second is quite ...
8
votes
3answers
984 views

Y combinator, Infinite types and Anonymous recursion in Haskell

I was trying to solve the maximal subsequence sum problem and came up with a neato solution msss :: (Ord a, Num a) => [a] -> a msss = f 0 0 f gmax _ [] = gmax f gmax lmax (x:xs) = let g = ...
2
votes
2answers
316 views

Non-Recursive list function with Y Combinator

Note: This is kind of homework, kind of not - the end goal is to have a function that produces a powerset of a set of numbers supplied to the function as a list of numbers. I ahe a recursive version ...
24
votes
8answers
13k views

In Scheme, how do you use lambda to create a recursive function?

I'm in a Scheme class and I was curious about writing a recursive function without using define. The main problem, of course, is that you cannot call a function within itself if it doesn't have a name....
1
vote
4answers
2k views

Recursion with anonymous function [duplicate]

Possible Duplicates: javascript: recursive anonymous function? Anonymous recursive PHP functions I was wondering... Is it possible to do recursion with anonymous function? Here is one example: ...
3
votes
1answer
332 views

Howto: “letrec” in C# (lambda expression call within its definition)

Consider the factorial function defined within a method body as a lambda expression and assigned to a variable: Func<int, int> factfail = n => { if (n == 0) return 1; else ...
5
votes
5answers
596 views

Does “Anonymous Recursion” work in .NET? It does in Mono

I surfed into this site a few days ago on "Anonymous Recursion in C#". The thrust of the article is that the following code will not work in C#: Func<int, int> fib = n => n > 1 ? fib(n - ...