Scheme/Lisp Programming Help | INFJ Forum

Scheme/Lisp Programming Help

foggymask

One
Feb 21, 2012
1
1
0
MBTI
ISTP
Enneagram
9 Omni
Hey everyone, I am trying to write a lambda function that will return with another function when you plug in certain numbers. I could really use some help understanding it. Here is the actual problem:

Often times in programming it will make sense to generalize a problem. One such way to create
a function to calculate a solution. You have learned how to define functions that return a value,
but in Scheme you can also define functions that return new functions as their return value.
Take the quadratic functions f(x) = x^2 + 2x + 3 and f(x) = 3x^2 + x + 1 for example. We don't
want to define a new function by hand for every quadratic polynomial we write. We can
generalize quadratic functions to f(x) = ax^2 + bx + c.
Your job is to write a function that takes the coefficients a, b, and c as arguments and returns a
function (using lambda) that can be evaluated at any x.
(define (gen-poly a b c))
(define test-poly (gen-poly 1 1 1))
(test-poly 1) ; returns 3
 
  • Like
Reactions: Jexocuha
What does it matter? It is all gobbodly gook anyway.
 
  • Like
Reactions: Jexocuha