aboutsummaryrefslogtreecommitdiff
path: root/sem7/pp/lec3.scm
diff options
context:
space:
mode:
Diffstat (limited to 'sem7/pp/lec3.scm')
-rw-r--r--sem7/pp/lec3.scm106
1 files changed, 53 insertions, 53 deletions
diff --git a/sem7/pp/lec3.scm b/sem7/pp/lec3.scm
index 42b30e1..3e6dbfe 100644
--- a/sem7/pp/lec3.scm
+++ b/sem7/pp/lec3.scm
@@ -1,20 +1,20 @@
(define (to-string thing)
(let ([format-pair-tail
- (lambda (tail)
- (apply string-append (cond [(null? tail) (list "")]
- [(pair? tail) (list " " (to-string tail))]
- [else (list " . " (to-string tail))])))
- ])
+ (lambda (tail)
+ (apply string-append (cond [(null? tail) (list "")]
+ [(pair? tail) (list " " (to-string tail))]
+ [else (list " . " (to-string tail))])))
+ ])
(cond [(number? thing) (number->string thing)]
- [(symbol? thing) (symbol->string thing)]
- [(null? thing) "()"]
- [(procedure? thing) "#function#"]
- [(pair? thing) (string-append
- (to-string (car thing))
- (format-pair-tail (cdr thing)))]
- [(string? thing) thing]
- [else "?"]
- )))
+ [(symbol? thing) (symbol->string thing)]
+ [(null? thing) "()"]
+ [(procedure? thing) "#function#"]
+ [(pair? thing) (string-append
+ (to-string (car thing))
+ (format-pair-tail (cdr thing)))]
+ [(string? thing) thing]
+ [else "?"]
+ )))
(define (send obj msg . para)
(let ((method (obj obj msg)))
@@ -28,34 +28,34 @@
(let ([whoami 'object])
(lambda (self msg)
(cond [(eq? msg 'pretty-str) (lambda () (to-string (send self 'pretty)))]
- [(eq? msg 'pretty) (lambda () (list whoami))]
- [(eq? msg 'type-of) (lambda () whoami)]
- [(eq? msg 'class-of) (lambda () object)]
- [else (errorf object "msg ~a not found" msg)])
+ [(eq? msg 'pretty) (lambda () (list whoami))]
+ [(eq? msg 'type-of) (lambda () whoami)]
+ [(eq? msg 'class-of) (lambda () object)]
+ [else (errorf object "msg ~a not found" msg)])
)))
(define (point x y)
(let ([whoami 'point]
- [super (object)])
+ [super (object)])
(lambda (self msg)
(cond [(eq? msg 'getx) (lambda () x)]
- [(eq? msg 'gety) (lambda () y)]
- [(eq? msg 'add) (lambda (other)
- (new-instance (send self 'class-of)
- (+ x (send other 'getx))
- (+ y (send other 'gety))
- ))]
- [(eq? msg 'pretty) (lambda () (list whoami x y))]
- [(eq? msg 'move) (lambda (dx dy)
- (send self 'add (new-instance point dx dy)))]
- [(eq? msg 'type-of) (lambda () whoami)]
- [(eq? msg 'class-of) (lambda () point)]
- [(eq? msg 'with-color) (lambda (color)
- (new-instance color-point
- (send self 'getx)
- (send self 'gety)
- color))]
- [else (super self msg)]))
+ [(eq? msg 'gety) (lambda () y)]
+ [(eq? msg 'add) (lambda (other)
+ (new-instance (send self 'class-of)
+ (+ x (send other 'getx))
+ (+ y (send other 'gety))
+ ))]
+ [(eq? msg 'pretty) (lambda () (list whoami x y))]
+ [(eq? msg 'move) (lambda (dx dy)
+ (send self 'add (new-instance point dx dy)))]
+ [(eq? msg 'type-of) (lambda () whoami)]
+ [(eq? msg 'class-of) (lambda () point)]
+ [(eq? msg 'with-color) (lambda (color)
+ (new-instance color-point
+ (send self 'getx)
+ (send self 'gety)
+ color))]
+ [else (super self msg)]))
))
@@ -64,18 +64,18 @@
(define (color-point x y . color)
(let ([color (if (null? color) 'green (car color))]
- [whoami 'color-point]
- [super (point x y)])
+ [whoami 'color-point]
+ [super (point x y)])
(lambda (self msg)
(cond [(eq? msg 'get-color) (lambda () color)]
- [(eq? msg 'type-of) (lambda () whoami)]
- [(eq? msg 'pretty) (lambda ()
- (list whoami
- (send self 'getx)
- (send self 'gety)
- (send self 'get-color)))]
- [(eq? msg 'class-of) (lambda () color-point)]
- [else (super self msg)]))
+ [(eq? msg 'type-of) (lambda () whoami)]
+ [(eq? msg 'pretty) (lambda ()
+ (list whoami
+ (send self 'getx)
+ (send self 'gety)
+ (send self 'get-color)))]
+ [(eq? msg 'class-of) (lambda () color-point)]
+ [else (super self msg)]))
))
;;# Exercise 3.7
@@ -85,10 +85,10 @@
(z 3)
(v 5))
(cons x
- (call/cc (lambda (e)
- (cons y
- (cons z
- (if (even? v) v (e (+ v 1)))))))))
+ (call/cc (lambda (e)
+ (cons y
+ (cons z
+ (if (even? v) v (e (+ v 1)))))))))
;; Okay lets start by looking at it:
;; Okay, we define x y z and v
;; Then we create a cons with x and the continuations, so the result must be
@@ -107,8 +107,8 @@
(k (* a b)))
(define (dist a b c k)
(mult a c (lambda (v)
- (mult 4 v (lambda (v1)
- (mult b b (lambda (v2)
- (sub v2 v1 k))))))))
+ (mult 4 v (lambda (v1)
+ (mult b b (lambda (v2)
+ (sub v2 v1 k))))))))
(define dist-old (lambda (a b c) (- (* b b) (* 4 a c))))