zoukankan      html  css  js  c++  java
  • ch17

    原来不一样的地方还挺多的,比如drracket不支持嵌套定义,

    (define (a b)
      b
      (define (c d)
        d))

    就是define: expected only one expression for the function body, but found 1 extra part。 也就是b和(define (c d) d)就是two part了。

    (define (a b)
     
      (define (c d)
        d))

    就是define: found a definition that is not at the top level。

    所以还是用官方推荐的MIT/GNU SCHEME, 可惜的就是EMACS的快捷键不大会用。

    /////////////////////////////////////////////////////////////////

    drracket的cons语法好像和scheme有点不一样,scheme里是点对,drracket里cons的两个参数第二个要求是个list,也就是(cons empty 1)和(cons 1 empty)之中,前者是不合法的。

    17.1.1 用课本中给出的replace-eol-with 实现和自带的append函数一样功能的函数,纯属练手。

    (define (replace-eol-with alon1 alon2)
      (cond
        ((empty? alon1) alon2)
        (else (cons (first alon1) (replace-eol-with (rest alon1)
      alon2)))))
    (define (our-append alon1 alon2 alon3)
      (replace-eol-with
       (replace-eol-with alon1 alon2) alon3))

     17.1.2 将给出的符号表和数表中的符号和数一 一配对,设计函数返回所有情况。写这个让我感到辅助函数的重要性...想用一个函数结果会让思路混乱。

    example:(cross '(a b c) '(1 2))

    output:(list (list 'a 1) (list 'a 2) (list 'b 1) (list 'b 2) (list 'c 1) (list 'c 2))

    按照书中的分析方法:

    1.Data Definition

    2.describe

    3.list template

    4.example

    5.define

    6.test

    (define (cross los lon)
      (cond
        ((empty? los)
         empty) 
        (else
         (append(pairs(first los)lon)(cross(rest los) lon)))))
    (define (pairs s lon)
      (cond
        ((empty? lon)
         empty)
        (else
         (cons(list s (first lon)) (pairs s (rest lon))))))
  • 相关阅读:
    javascript学习笔记-数据类型
    chrome console.log API
    Mysql下SELECT的结果集作为UPDATE的WHERE条件时的SQL语法
    Ajax、Comet、Websocket、SSE
    Model View Controller(MVC) in PHP
    区别Transform、Transition、Animation
    WAI-ARIA无障碍网页应用属性完全展示
    理解 PHP output buffer
    清除Jquery动画的队列
    git常用命令
  • 原文地址:https://www.cnblogs.com/autoria/p/4739241.html
Copyright © 2011-2022 走看看