|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming | |
What Programming Language Should I Learn?
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#21 (permalink) | ||||||||||||||
|
Off By 340 Undecillion
|
Quote:
![]() It will take only a little work to get our sum function to work with this very general and useful tool. Below is a function that is a little more general than even mathematical definition of sigma. Sigma takes as its arguments a function to apply to an input, a stopping condition, a way to get to the next sum value, and the starting data m. One of the really cool things in Scheme is that a function can be passed exactly like any other variable. Code:
(define (sigma function next condition m)
(if (condition m)
0
(+ (function m)
(sigma function condition next (next m)))))
(sigma car cdr null? b) Now how about a sum of squares from 1 to 49? like 1^2 +2^2 + 3^2 + 4^2 ... all you need is: Code:
(sigma square add1 lessthan50 1) (define (add1 x) (+ x 1)) (define (lessthan50 y) (> 50 y))
__________________
Congratulations! You have found the secret text! You get a cookie.
Last edited by The Bartender Paradox : 07-02-08 at 05:40 PM. |
||||||||||||||
|
|
|
|
#22 (permalink) | ||||||||||||
|
Mmmm! Toast!
|
__________________
Rocket 3 down-payment fund: [|||||||||] $6k e6750 @ 3.2 Ghz (400x8) - 7k ppd GPU+SMP
|
||||||||||||
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|