|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming | |
Scheme Procedural Abstraction
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | |||||||||||||
|
Audiophile
|
I'm trying to write a really small program in scheme (lisp) that uses procedural abstraction, here is an example:
__________________(define (make-exponent x) (lambda (x) (expt x n))) (define square (make-exponent 2)) (square 2) ---> 4 (square 6) ---> 36 (define cube (make-expt 3)) (cube 3) ---> 9 You can see how this works. Anyway I am supposed to write a function (calling it fmap) that takes as its arguments, a function f and a list l, and returns a list containing the results of f applied to l. Seems easy enough, but I just can't do it. I can see how the above example works but it's just not clicking for me. Does anyone even know scheme? lol =)
|
|||||||||||||
|
|
|
|
|
#2 (permalink) | |||||||||||||
|
Audiophile
|
Edit: Well the post took out what little formatting i gave it, and i obviously cant multiply because I had 3^3 = 9...
__________________And apparently i don't know how to use the edit button. . .As I made a second post -_-
|
|||||||||||||
|
|
|
|
|
#3 (permalink) | |||||||||||||
|
New to Overclock.net
|
use [code][/code] and you can save the formatting problem.
__________________I'm diong scheme now actually. is there any restrictions on what the function can be? is it supposed to be like this function (x y z) => (function(x) function(y) function(z)) or can you do something like this + (x y z) => x+y+z ?
Last edited by serge2k : 2 Weeks Ago at 03:12 AM |
|||||||||||||
|
|
|
|
|
#4 (permalink) | |||||||||||||
|
Audiophile
|
Code:
(define (fmap func list)
(cond
((null? list) '())
(#t(func list))))
Code:
(define (fmap2 func list list2)
(cond
((null? list) '())
(#t(func list list2))))
Code:
(fmap2 eq? 'a 'b) And now as this was the first part of my assignment, I have to go back and rewrite some previous functions to use this fmap instead of the cars/cdrs/etc. they currently use. I assume all I have to do is pass that code into fmap instead of using it in my original. . .
|
|||||||||||||
|
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|