簡體   English   中英

The Little Schemer 是否有“對齊”功能的示例?

[英]Is there an example of the "align" function from The Little Schemer?

The Little Schemer 的第 9 章中:

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

書中的大部分函數都有例子,例子一般都有詳細的講解,但不是這個函數。

我不明白如何使用這個功能,所以我無法理解后面的功能。 我在網上找不到這個函數的例子。

你能給我舉一些例子嗎?

我找到了這個存儲庫,其中包含代碼和一些示例:

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

對齊的例子:

(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))))))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM