Below is a simple program developed in the Scheme programming language to illustrate how functional languages operate. This particular program will transpose a matrix. See if you can understand the functional logic behind the program.
(define transpose
(lambda (lis)
(cond
((null? lis) ())
((null? (car lis)) ())
(else
(cons (append (map car lis)) (transpose (map cdr lis)))
)
)
)
)
(transpose '( (1 2 3 4) (4 5 6 7) (7 8 9 0) ))
When run, the output is:
((1 4 7) (2 5 8) (3 6 9) (4 7 0)) >


