zoukankan      html  css  js  c++  java
  • SICP之应用序和正则序

    以一个题目来说明

    (define (square x) (* x x))
    (define (sum-squares x y) 
      (+ (square x) (square y)))
    (define (f a)
       (sum-squares (+ a 1) (* a 2)))  
    

    列如求 (f 5)

    应用序

    应用序则是先一步步替换子组合求值再去应用的为应用序(“evaluate the arguments and then apply”翻译为“先求参数值再应用”)

    `(f 5)`展开
    `(sum-squares (+ a 1) (* a 2)))`
    `5`替换 `a`为
    `(sum-squares (+ 5 1) (* 5 2)))`
    直接进行子项求值
    `(+ 5 1)`求值为`6`,`(* 5 2)`求值`10` 替换后为 `(sum-squares 6 10)`
    替换`sum-squares`
    `(+ (square 6) (square 10))`
    替换`square`
    `(+ (* 6 6) (* 10 10))`
    最后求和 `136`
    上面的过程可以看出是一步步传入参数值去计算子项后最后得出结果

    正则序

    正则序则是一步步替换所有过程直至最原始的符号(“fully expand and then reduce”翻译为完全展开后归约)

    `(f 5)`展开
    `(sum-squares (+ 5 1) (* 5 2)))`展开
    `(+ (square (+ 5 1)) (square (* 5 2)))`展开
    `(+ (* (+ 5 1) (+ 5 1)) (* (* 5 2) (* 5 2)))`最后直接归约求和 `136`

    可以看出正则就是把所有过程函数全部替换调直到最原始的一些过程函数(+ * / 这些)最后归约。

  • 相关阅读:
    NORDIC BLE MAC ADDR
    dbm和发射功率得对照表
    git切换账号邮箱
    文件编码问题造成的汉字输出乱码问题
    自定义printf 打印函数
    NORDIC 烧录BLE协议栈后不能用JLINK仿真bootloader问题及修改方案
    NORDIC BLE升级
    NORDIC ble RSSI
    NORDIC 错误文件
    NORDIC 协议栈下使用硬件定时器
  • 原文地址:https://www.cnblogs.com/yantt/p/sicp-zhi-ying-yong-xu-he-zheng-ze-xu.html
Copyright © 2011-2022 走看看