I've started a new personal development blog. Please check it out if you are interested in that argument.
« May 2009 | Main | August 2009 »
I've started a new personal development blog. Please check it out if you are interested in that argument.
Posted at 03:49 PM | Permalink | Comments (0) | TrackBack (0)
I'm going to port all the sicp exercises on the new site. If you are interested in them, you should follow this page. Enjoy
Posted at 02:01 PM in Programming | Permalink | Comments (0) | TrackBack (0)
I will skip this last part of chapter 2 because it is to much work for me. If you are interested in it, you can take a look at this post.
Posted at 03:05 PM in Programming | Permalink | Comments (0) | TrackBack (0)
Introduction
Posted at 02:42 PM in Programming | Permalink | Comments (0) | TrackBack (0)
Introduction
(define (install-project)
(define (project-complex x) (make-real (real-part x))) (define (project-real x) (make-rat (round x) 1)) (define (project-rational x) (numer x)) (put 'project '(complex) project-complex) (put 'project '(real) project-real) (put 'project '(rational) project-rational))(define (can-be-lowered? n)
(and (not (= (type-tag n) 'scheme-number)) (equ? n (raise (project n)))))
(define (drop n) (if (can-be-lowered? n) (drop (project n)) n))(define (apply-generic op . args)
(let ((type-tags (map type-tag args))) (let ((proc (get op type-tags))) (if proc (drop (apply proc (map contents args))) (if (= (length args) 2) (let ((type1 (car type-tags)) (type2 (cadr type-tags)) (a1 (car args)) (a2 (cadr args))) (let ((t1->t2 (get-coercion type1 type2)) (t2->t1 (get-coercion type2 type1))) (cond (t1->t2 (apply-generic op (t1->t2 a1) a2)) (t2->t1 (apply-generic op a1 (t2->t1 a2))) (else (error "No method for these types" (list op type-tags)))))) (error "No method for these types" (list op type-tags)))))))Posted at 02:36 PM in Programming | Permalink | Comments (0) | TrackBack (0)
(define tower '(integer rational real complex))
Posted at 02:17 PM in Programming | Permalink | Comments (0) | TrackBack (0)
Introduction
(define (install-raise)
(put 'raise '(scheme-number) (lambda (x) (make-rat x 1))) (put 'raise '(rational) (lambda (x) (make-real (* (/ (numer x) (denom x)) 1.0)))) (put 'raise '(real) (lambda (x) (make-from-real-imag x 0))))Posted at 02:05 PM in Programming | Permalink | Comments (0) | TrackBack (0)
Introduction
(define (apply-generic op . args)
(let ((type-tags (map type-tag args))) (let ((proc (get op type-tags))) (if proc (apply proc (map contents args)) (if (> (length args) 2) (apply-generic op (apply-generic op (car args) (cadr args)) (cddr args)) ; I assume otherwise there are 2 arguments (let ((type1 (car type-tags)) (type2 (cadr type-tags)) (a1 (car args)) (a2 (cadr args))) (let ((t1->t2 (get-coercion type1 type2)) (t2->t1 (get-coercion type2 type1))) (cond (t1->t2 (apply-generic op (t1->t2 a1) a2)) (t2->t1 (apply-generic op a1 (t2->t1 a2))) (else (error "No method for these types" (list op type-tags)))))) (error "No method for these types" (list op type-tags)))))))Posted at 01:50 PM in Programming | Permalink | Comments (0) | TrackBack (0)
Introduction
(define (scheme-number->scheme-number n) n)
(define (complex->complex z) z)(put-coercion 'scheme-number 'scheme-number scheme-number->scheme-number)(put-coercion 'complex 'complex complex->complex);; following added to Scheme-number package
(put 'exp '(scheme-number scheme-number) (lambda (x y) (tag (expt x y)))) ; using primitive expt(define (apply-generic op . args)
(let ((type-tags (map type-tag args))) (let ((proc (get op type-tags))) (if proc (apply proc (map contents args)) (if (and (= (length args) 2) (not (= (type-tag (car type-tags)) (type-tag (cadr type-tags))))) (let ((type1 (car type-tags)) (type2 (cadr type-tags)) (a1 (car args)) (a2 (cadr args))) (let ((t1->t2 (get-coercion type1 type2)) (t2->t1 (get-coercion type2 type1))) (cond (t1->t2 (apply-generic op (t1->t2 a1) a2)) (t2->t1 (apply-generic op a1 (t2->t1 a2))) (else (error "No method for these types" (list op type-tags)))))) (error "No method for these types" (list op type-tags))))))))Posted at 01:37 PM in Programming | Permalink | Comments (0) | TrackBack (0)