Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming

Reply
 
LinkBack Thread Tools
Old 2 Weeks Ago   #1 (permalink)
Audiophile
 
Calihan's Avatar
 
intel nvidia

Join Date: Jun 2006
Location: USA, Minnestoa
Posts: 111

Rep: 2 Calihan Unknown
Unique Rep: 2
Trader Rating: 2
Default Scheme Procedural Abstraction

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 =)
__________________
System: Wise Man
CPU
I7 920 D0
Motherboard
ASROCK x58 Extreme
Memory
G.SKILL Trident 6GB (3 x 2GB) DDR3 2000
Graphics Card
evga 8800 gts 512
Hard Drive
70 gig raptor / 200 gig storage / WD6400aaks
Sound Card
0404 usb
Power Supply
oczgamexstream 700
Case
CM Stacker (I'd like an Antec Solo)
CPU cooling
Vendetta 2
GPU cooling
Stock
OS
Windows Vista x64
Monitor
Samsung 245T
Calihan is offline   Reply With Quote
Old 2 Weeks Ago   #2 (permalink)
Audiophile
 
Calihan's Avatar
 
intel nvidia

Join Date: Jun 2006
Location: USA, Minnestoa
Posts: 111

Rep: 2 Calihan Unknown
Unique Rep: 2
Trader Rating: 2
Default

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 -_-
__________________
System: Wise Man
CPU
I7 920 D0
Motherboard
ASROCK x58 Extreme
Memory
G.SKILL Trident 6GB (3 x 2GB) DDR3 2000
Graphics Card
evga 8800 gts 512
Hard Drive
70 gig raptor / 200 gig storage / WD6400aaks
Sound Card
0404 usb
Power Supply
oczgamexstream 700
Case
CM Stacker (I'd like an Antec Solo)
CPU cooling
Vendetta 2
GPU cooling
Stock
OS
Windows Vista x64
Monitor
Samsung 245T
Calihan is offline   Reply With Quote
Old 2 Weeks Ago   #3 (permalink)
New to Overclock.net
 
intel nvidia

Join Date: Nov 2007
Location: Surrey, BC, Canada
Posts: 272

Rep: 14 serge2k Unknown
Unique Rep: 14
Trader Rating: 1
Default

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

?
__________________
System: The Black Box
CPU
E6750
Motherboard
Asus P5N-E SLI
Memory
2GB DDR-2 800 MHz
Graphics Card
EVGA 8800 GTS 640
Hard Drive
2x250GB Seagate in Raid 0, 2x1TB WD Caviar Blacks
Sound Card
integrated
Power Supply
Antec Earthwatts 500W
Case
Antec Sonata 3
CPU cooling
Xigmatek HDT S1283
GPU cooling
stock
OS
Windows 7 Ultimate x64
Monitor
22" LG

Last edited by serge2k : 2 Weeks Ago at 03:12 AM
serge2k is offline   Reply With Quote
Old 2 Weeks Ago   #4 (permalink)
Audiophile
 
Calihan's Avatar
 
intel nvidia

Join Date: Jun 2006
Location: USA, Minnestoa
Posts: 111

Rep: 2 Calihan Unknown
Unique Rep: 2
Trader Rating: 2
Default

Code:
(define (fmap func list)
  (cond
    ((null? list) '())
    (#t(func list))))
I don't know why I was having trouble with this. That's the working code right there. Please note that this function assumes that the function you are going to use only takes 1 parameter (list, atom, etc.) If you tried to use, let's say eq? with it, you wouldn't be able to pass in 2 things to compare. And also I just threw in that check for the null list as it was something related to my assignment that I didn't include last time.

Code:
(define (fmap2 func list list2)
  (cond
    ((null? list) '())
    (#t(func list list2))))
Thats if you wanted to use eq?, as it will let you pass in 2 parameters. I'm sorry that I was a little confusing in my original post.

Code:
(fmap2 eq? 'a 'b)
This would return a #f, like we assume it should.

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. . .
__________________
System: Wise Man
CPU
I7 920 D0
Motherboard
ASROCK x58 Extreme
Memory
G.SKILL Trident 6GB (3 x 2GB) DDR3 2000
Graphics Card
evga 8800 gts 512
Hard Drive
70 gig raptor / 200 gig storage / WD6400aaks
Sound Card
0404 usb
Power Supply
oczgamexstream 700
Case
CM Stacker (I'd like an Antec Solo)
CPU cooling
Vendetta 2
GPU cooling
Stock
OS
Windows Vista x64
Monitor
Samsung 245T
Calihan is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -5. The time now is 04:45 PM.


Overclock.net is a Carbon Neutral Site Creative Commons License

Terms of Service / Forum Rules | Privacy Policy | DMCA Info | Advertising | Become an Official Vendor
Copyright © 2009 Shogun Interactive Development. Most rights reserved.
Page generated in 0.11271 seconds with 8 queries