【问题标题】:Is there an example of the "align" function from The Little Schemer?有来自 The Little Schemer 的“对齐”功能的示例吗?
【发布时间】:2021-07-22 02:06:34
【问题描述】:

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

书中大部分函数都有例子,例子一般都有详细讲解,但没有这个函数。

我不明白如何使用这个功能,所以我无法理解后面的功能。我在网上找不到这个函数的例子。

你能给我一些例子吗?

【问题讨论】:

  • (对齐 1)。 (对齐'((1 2)3))。 (对齐'(1))。
  • 仍然不明白这个函数的目的是什么(除了与上一页的kee-looking进行比较)。 (align '((1 2) 3)) 将返回与(shift '((1 2) 3)) 完全相同的内容,在这种情况下为'(1 (2 3)) 为什么叫对齐?它似乎并没有真正对齐任何东西 oO

标签: scheme the-little-schemer


【解决方案1】:

我找到了包含代码和一些示例的存储库:

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

【讨论】:

    猜你喜欢
    • 2010-12-30
    • 1970-01-01
    • 2011-10-23
    • 2012-05-16
    • 2011-11-10
    • 2011-06-14
    • 2014-06-28
    • 2012-09-06
    • 2015-10-22
    相关资源
    最近更新 更多