anonymous-recursion

Generating powerset in one function, no explicit recursion, and using only simplest primitives in Racket

北城余情 提交于 2021-01-04 02:10:01
问题 Note: this is a bonus for homework, but I have spent way too long on trying things to no avail. Help is much appreciated, but not necessary I suppose. Premise: generate a powerset for a list of numbers, but without using any helpers, explicit recursion, looping, or functions/constants other than cons , first , rest , empty? , empty , else , lambda , and cond , while using only one define on the language level Intermediate Student with Lambda . The order of the powerset does not matter. What I

Generating powerset in one function, no explicit recursion, and using only simplest primitives in Racket

微笑、不失礼 提交于 2021-01-04 01:58:54
问题 Note: this is a bonus for homework, but I have spent way too long on trying things to no avail. Help is much appreciated, but not necessary I suppose. Premise: generate a powerset for a list of numbers, but without using any helpers, explicit recursion, looping, or functions/constants other than cons , first , rest , empty? , empty , else , lambda , and cond , while using only one define on the language level Intermediate Student with Lambda . The order of the powerset does not matter. What I

List function with Y combinator does no recursion, why?

耗尽温柔 提交于 2020-12-31 07:00:17
问题 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 have a recursive version of the function but I now need to find some ways of replacing each explicitly recursive function in the solution I have ( append , mapm etc.) with an equivalent lambda-only expression. As such, I am starting with smaller problems and hope to combine them all to write a full function. I've

List function with Y combinator does no recursion, why?

半世苍凉 提交于 2020-12-31 06:56:34
问题 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 have a recursive version of the function but I now need to find some ways of replacing each explicitly recursive function in the solution I have ( append , mapm etc.) with an equivalent lambda-only expression. As such, I am starting with smaller problems and hope to combine them all to write a full function. I've

The mechanism of anonymous function to call itself in Scheme?

不羁的心 提交于 2020-01-03 14:07:26
问题 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))))))) eternity) (define eternity (lambda (x) (eternity x))) The code is to determine the empty list, otherwise it never stops. Why is the " len " not recursion? 回答1: Although it can be dangerous to apply textual substitution to Lisp forms (since there are dangers of multiple evaluation, etc.), in this case it may help to look at this form and see

The mechanism of anonymous function to call itself in Scheme?

南楼画角 提交于 2020-01-03 14:07:09
问题 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))))))) eternity) (define eternity (lambda (x) (eternity x))) The code is to determine the empty list, otherwise it never stops. Why is the " len " not recursion? 回答1: Although it can be dangerous to apply textual substitution to Lisp forms (since there are dangers of multiple evaluation, etc.), in this case it may help to look at this form and see

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

扶醉桌前 提交于 2019-12-22 10:46:39
问题 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-length)) (lambda (mk-length) (lambda (l) (cond ((null? l ) 0) (else (add1 ((mk-length eternity ) (cdr l)))))))) '(1)) I want to study step by step, and want to write the similar function that supports only lists of length smaller than or equal to 2 . Please, don't answer this question by offering code like: (((lambda (mk-length) ; B.

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

爷,独闯天下 提交于 2019-12-10 14:09:49
问题 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 - 1) + fib(n - 2) : n; The article then goes into some detail about how to use currying and the Y-combinator to get back to "Anonymous Recursion" in C#. This is pretty interesting but a tad complex for my everyday coding I am afraid. At this point at least... I like to see stuff for myself so I opened the Mono

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

Deadly 提交于 2019-12-10 10:47:55
问题 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 itself): ((lambda (mk-length) (mk-length mk-length)) (lambda (mk-length) ((lambda (length) (lambda (l) (cond ((null? l) 0) (else (add1 (length (cdr l))))))) (mk-length mk-length)))) the part (mk-length mk-length) , will never return and will be infinitely applying itself to itself: Because we just

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

情到浓时终转凉″ 提交于 2019-12-07 03:56:15
问题 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 combinator and friends, e.g.: http://www.ece.uc.edu/~franco/C511/html/Scheme/ycomb.html http://okmij.org/ftp/Computation/fixed-point-combinators.html http://www.angelfire.com/tx4/cus/combinator/birds.html http://en.wikipedia.org/wiki/Fixed-point_combinator When I went to implement "letrec" semantics