All Questions
Tagged with functional-programming scheme
627 questions
0
votes
2
answers
152
views
Is environment model necessary for higher-order procedures?
When learning SICP, 6.001 lec15 has:
A good understanding of the environment model tells me why (IMHO) C++ will never have a fully-functional map, filter, and fold-right/fold-left procedures that are ...
1
vote
1
answer
59
views
Is an iterative process that returns a list with size that increases by iteration any different from an one that returns a scalar?
This actually comes from me initially misreading the text of Exercise 1.12.
The request is indeed to
Write a procedure that computes elements of Pascal's triangle by means of a recursive process.
I ...
0
votes
2
answers
283
views
What is (Y Y), the Y-combinator applied to itself?
In Chapter 9 of The Little Schemer, the authors introduce the Y-combinator and the penultimate question asks: "What is (Y Y)". They answer: "Who knows, but it works very hard."
I ...
2
votes
3
answers
522
views
Flattening a list of lists in racket
I'm working on an assignment in Racket (Intermediate Student with lambda) and I'm trying to make a helper function which flattens a list of lists. I'm not allowed to use recursion, nor can I use apply....
1
vote
2
answers
119
views
why is `(((call/cc (lambda (k) k)) (lambda (x) x)) "HEY!")` evaluated to "HEY!"?
I am reading The scheme programming language and seeing this example in continuation section:
(((call/cc (lambda (k) k)) (lambda (x) x)) "HEY!") => "HEY!"
I cannot figure out ...
1
vote
3
answers
90
views
How to pass on a lambda that produces a list to a procedure that expects a list?
I have the following procedures:
(define (remove-first f)
(rest f))
(define (sty f)
(remove-first (lambda (x) (map f x))))
(define (square x)
(* x x))
(define new-func (sty square))
(new-...
2
votes
6
answers
114
views
Implementing last-non-zero without continuations
last-non-zero takes a list of numbers and return the last cdr whose car is 0.
So, I can implement it using continuations, but how do I do this with natural recursion.
(define last-non-zero
(lambda (...
1
vote
1
answer
227
views
Delete common elements in two lists
I was trying to implement a function that deletes all common elements in two lists using Scheme.
Here is the function I wrote.
#| delete elem from lis|#
(define (delete ele lis)
(cond
((null? ...
1
vote
1
answer
86
views
How to get a value other than a boolean in a predicate?
I am trying to add an element into a list if it is zero as part of a recursive function that removes all non-zeroes from a list. if it is non-zero then I just want the code to continue on. Here's ...
0
votes
1
answer
42
views
Exiting from a recursive call in a functional language
I am currently learning racket and am having a hard time understanding how to program in a functional language. I am trying to have the function first-item match the first element of my list to either ...
0
votes
2
answers
240
views
How does scramble function works? (Chapter 1 of The Seasoned Schemer)
According to the book, this is what the function definition is,
The function scramble takes a non-empty tuple in which no argument is greater than its own index and returns a tuple of same length. ...
1
vote
1
answer
126
views
Representing a queue as a procedure with local state
Section §2.1.3 at page 90 explains, with a very clear example, that first class functions in a language make functions themselves and data be the same thing looked at from different perspectives, or, ...
0
votes
4
answers
656
views
Reversing a list in Scheme with some restrictions
I'm trying to reverse a list in Scheme, but I can only use define, car, cdr, list?, null?, if, cond, cons, display, begin, and any operators. I cannot use append, loops (must be pure recursion), ...
0
votes
2
answers
245
views
Making blocks of matrix (represented by list) in racket
I have a task where I need to divide the given matrix into blocks (width and height are also given and suite the matrix). The metrix is represented by a list of lists, where every list is a row in the ...
0
votes
1
answer
190
views
Racket AND logical statement or nested if's with struct
I'm trying to just make a simple Racket block of code with an AND or just nested-if logical statement. This is supposed to just specify if variable hours is above 0 and below 24 hours and minutes is ...