47 lines
1.3 KiB
Plaintext
47 lines
1.3 KiB
Plaintext
(define :+ +)
|
|
(define (+ a b)
|
|
(if (vector? a)
|
|
(if (vector? b)
|
|
(vector-map :+ a b)
|
|
(error "error:" "not applicable (+ vector non-vector)"))
|
|
(if (vector? b)
|
|
(error "error:" "not applicable (+ non-vector vector)")
|
|
(:+ a b))))
|
|
|
|
(define :- -)
|
|
(define (- a b)
|
|
(if (vector? a)
|
|
(if (vector? b)
|
|
(vector-map :- a b)
|
|
(error "error:" "not applicable (+ vector non-vector)"))
|
|
(if (vector? b)
|
|
(error "error:" "not applicable (+ non-vector vector)")
|
|
(:- a b))))
|
|
|
|
(define :* *)
|
|
(define (* a b)
|
|
(if (vector? a)
|
|
(if (not (vector? b))
|
|
(vector-map (lambda (x) (:* x b)) a)
|
|
(error "error:" "not applicable (* vector vector)"))
|
|
(if (vector? b)
|
|
(error "error:" "not applicable (* scalar vector)")
|
|
(:* a b))))
|
|
|
|
(define :/ /)
|
|
(define (/ a b)
|
|
(if (vector? a)
|
|
(if (not (vector? b))
|
|
(vector-map (lambda (x) (:/ x b)) a)
|
|
(error "error:" "not applicable (/ vector vector)"))
|
|
(if (vector? b)
|
|
(error "error:" "not applicable (/ scalar vector)")
|
|
(:/ a b))))
|
|
|
|
(define x [1 2 3 4 5])
|
|
(define y [7 8 5 4 2])
|
|
(print x " + " y " = " (+ x y))
|
|
(print x " - " y " = " (- x y))
|
|
(print x " * " 7 " = " (* x 7))
|
|
(print x " / " 7 " = " (/ x 7))
|