Tuesday, September 21, 2004

Scheme is Awesome

Scheme is still one of my favourite programming languages. This ask.metafilter thread is turning out to be the best collection of Scheme learning resources I've seen. Stealing some of the links:Just to illustrate how awesome scheme is, here's a quick sort implementaiton that is much more elegant and intuitive than anything in an imperative language like C:
(define merge

(lambda (ls-1 ls-2)
(let loop ((rest-1 ls-1)
(rest-2 ls-2)
(merged '()))
(cond ((null? rest-1) (revappend merged rest-2))
((null? rest-2) (revappend merged rest-1))
(else (let ((first-1 (car rest-1))
(first-2 (car rest-2)))
(if (< first-2 first-1)
(loop rest-1 (cdr rest-2) (cons first-2 merged))
(loop (cdr rest-1) rest-2 (cons first-1 merged)))))))))

(define revappend
(lambda (ls-1 ls-2)
(if (null? ls-1)
ls-2
(revappend (cdr ls-1) (cons (car ls-1) ls-2)))))
Basically everything in Scheme is a function, so the if, loop, etc. are all actually functions with the conditions and executable code as parameters to the function. This structure makes it simpler to mathematically prove various properties of algorithms implemented in Sheme and other functional languages.

By al - 10:49 p.m. |

    follow me on Twitter

    al's del.icio.us Links

    • www.flickr.com
      This is a Flickr badge showing public photos from dragonofsea. Make you own badge here.
    •  
    • (al)



    • Powered by Blogger