-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlect3a.scm
69 lines (56 loc) · 1.61 KB
/
lect3a.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
;; Program illustrating creation of custom data-structures
;; In particular, this shows the definition of 2D-vectors, along with
;; support for rudimentary operations on this new 'user-dfined TYPE' like vector addition,
;; scaling of a vector, etc.
;;
;; Author : Raghu Ugaré
;; Courtesy: the great teacher/author-s of SICP! <3 :)
(define make-vec cons)
(define xcor car)
(define ycor cdr)
(define make-segment cons)
(define seg-start car)
(define seg-end cdr)
(define (+vec v1 v2)
(make-vec (+ (xcor v1)
(xcor v2))
(+ (ycor v1)
(ycor v2))))
(define (scale v f)
(make-vec (* f (xcor v))
(* f (ycor v))))
(define a (make-vec 1 2))
(define b (make-vec 3 4))
(define sum (+vec a b))
(printf "a = ~a~n" a)
(printf "b = ~a\n" b)
(printf "a+b = sum = ~a~n~n" sum)
; List operations...! :)
; CDR-ing down a list...
(define (scale-list s l)
(if (null? l)
() ; was originally 'nil'
(cons (* s (car l))
(scale-list s (cdr l)))))
; The MAP procedure...!!! BEAUTY...!! <3 :)
; was initially 'map' but it seems to exist olready
(define (ragsMap p l)
(if (null? l)
() ; was originally 'nil' --can be replaced by the term 'nil :)
(cons (p (car l))
(ragsMap p (cdr l)))))
(define 1-to-4 (list 1 2 3 4))
1-to-4
(cdr (cdr (cdr (cdr 1-to-4))))
(scale-list 10 1-to-4)
; My own Map procedure...!!!
(ragsMap (lambda (x)(* 10 x)) 1-to-4)
(define (square x) (* x x))
(ragsMap square 1-to-4)
(ragsMap (lambda (x)(+ 10 x)) 1-to-4)
; Henderson-Escher problem...!
;(define (coord-map rect)
; (lambda (point)
; (+vec
; (+vec (scale)
; )