Some Simple Scheme Examples
A couple of basic scheme functions to demonstrate.
;Determines if a list is symmetric (returns true or false) (define (symmetric ls) (define size (- (length ls) 1)) (define middle (if (odd? size) (/ (- size 1) 2) (/ size 2))) (define (helper ref) (if (= middle ref) #t (if (eq? (list-ref ls ref) (list-ref ls (- size ref))) (helper (+ ref 1)) ()))) (helper 0)) ;Returns the sum of the numbers from a to b (define (next a) (+ a 1);put whatever operation you want in here. ) (define (sum a b);sum integers from a to b (if (> a b) 0 (+ a (sum (next a) b)) ) )

This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
Download this code in plain text format here