-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.rkt
More file actions
50 lines (41 loc) · 954 Bytes
/
Copy pathmap.rkt
File metadata and controls
50 lines (41 loc) · 954 Bytes
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
#lang racket
(define lst '(1 2 3 4))
(define lst2 '(9 8 7 6 5 4 3 2 1 0))
(define (map proc items)
(if (empty? items)
empty
(cons (proc (car items))
(map proc (cdr items)))))
(define (square x)
(* x x))
(define (scale-list items factor)
(if (null? items)
null
(cons (* (car items) factor)
(scale-list (cdr items) factor))))
(define (reverse lst)
(reverse-iter lst (-(length lst)1) ))
(define (reverse-iter list length)
(if (< length 0)
empty
;;(get list 0)
(cons (get list length) (reverse-iter list (- length 1)))
))
(define (length list)
(length-iter list 0)
)
(define (length-iter list count)
(if (empty? list)
count
(length-iter (cdr list) (+ count 1))
)
)
(define (get lst index)
(get-iter lst 0 index)
)
(define (get-iter lst count index)
(if (= index count)
(car lst)
(get-iter (cdr lst) (+ count 1) index)
)
)