3

In chapter 9 of The Little Schemer:

(define align
  (lambda (pora)
    (cond ((atom? pora) pora)
          ((a-pair? (first pora)) (align (shift pora)))
          (else (build (first pora)
                       (align (second pora)))))))

Most of the functions in the book have examples, and the examples are usually explained in detail, but not this function.

I don't understand how to use this function, and so I can't understand the functions that follow. I can't find examples of this function on the web.

Could you show me some examples?

Flux
  • 9,805
  • 5
  • 46
  • 92
wang kai
  • 1,673
  • 3
  • 12
  • 21
  • (align 1). (align '((1 2) 3)). (align '(1)). – Will Ness Jul 26 '21 at 20:26
  • Still do not get what was the intention of this function (except to make the comparison with `kee-looking` from the previous page). `(align '((1 2) 3))` will return exactly the same thing that `(shift '((1 2) 3))`, in this case `'(1 (2 3))` Why is it called align? It doesn't seem to align anything actually oO – Everton J. Carpes Dec 25 '21 at 18:11

1 Answers1

1

I have found this repository with both the code and some examples:

https://github.com/viswanathgs/The-Little-Schemer/blob/master/ch-09-and-again-and-again-and-again.ss

The examples for align:

(align '(a b))                     ; (a b)
(align '((a b) c))                 ; (a (b c))
(align '((a b) (c d)))             ; (a (b (c d)))
(align '((a (b c)) (((d e) f) g))) ; (a (b (c (d (e (f g))))))