Created
November 26, 2010 08:28
-
-
Save srikumarks/716417 to your computer and use it in GitHub Desktop.
Scheme interpretation of examples in muse-tab-syntax-example.scm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define m 10) | |
(define this-better-be-6 | |
(add 1 2 3)) | |
(define this-better-be-0 | |
(add)) | |
(define (five) 5) | |
(define (trpl x) | |
(add x x x)) | |
(define (g a b c) | |
(add a b c)) | |
(define (d/dx f) | |
(define delta 0.001) | |
(lambda (x) | |
(/ (- (f (+ x delta)) | |
(f x)) delta))) | |
(define (fib n) | |
(cond ((numeq n 0) | |
1) | |
((numeq n 1) | |
1) | |
(#t (+ (fib (- n 1)) | |
(fib (- n 2)))))) | |
(defstruct memo | |
(key ans)) | |
(define (memoize f) | |
(define memo-table | |
(box empty)) | |
(lambda args | |
(define lookup | |
(filter (lambda (v) | |
(equal? args | |
(memo-key v))) | |
(unbox memo-table))) | |
(if (empty? lookup) | |
(begin (set-box! memo-table | |
(cons (make-memo args | |
(apply f args)) | |
(unbox memo-table))) | |
(apply f args)) | |
(memo-ans (first lookup))))) | |
(define this-better-be-9 | |
((fn (n) | |
(mult n n)) | |
3)) | |
(let ((x 3) | |
(y 2)) | |
(+ x y)) | |
(let* ((x 3) | |
(y x)) | |
(+ x y)) | |
(letrec ((even? (lambda (n) | |
(if (zero? n) true | |
(odd? (- n 1))))) | |
(odd? (lambda (n) | |
(if (zero? n) false | |
(even? (- n 1)))))) | |
(list (odd? 10) | |
(even? 10))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment