zoukankan      html  css  js  c++  java
  • 【SICP练习】146 练习4.2

    练习4-2

    原文

    Exercise 4.2. Louis Reasoner plans to reorder the cond clauses in eval so that the clause for procedure applications appears before the clause for assignments. He argues that this will make the interpreter more efficient: Since programs usually contain more applications than assignments, definitions, and so on, his modified eval will usually check fewer clauses than the original eval before identifying the type of an expression.
    a. What is wrong with Louis’s plan? (Hint: What will Louis’s evaluator do with the expression (define x 3)?)
    b. Louis is upset that his plan didn’t work. He is willing to go to any lengths to make his evaluator recognize procedure applications before it checks for most other kinds of expressions. Help him by changing the syntax of the evaluated language so that procedure applications start with call. For example, instead of (factorial 3) we will now have to write (call factorial 3) and instead of (+ 1 2) we will have to write (call + 1 2).

    分析

    所有的序对都被当作应用。
    因为都是以call开始,所以先用cdr取出exp,再分别用car和cdr取出operator和operands即可。

     (define (application? exp) (tagged-list? exp 'call)) 
     (define (operator exp) (cadr exp)) 
     (define (operands exp) (cddr exp)) 



    感谢您的访问,希望对您有所帮助。 欢迎大家关注或收藏、评论或点赞。


    为使本文得到斧正和提问,转载请注明出处:
    http://blog.csdn.net/nomasp


    版权声明:本文为 NoMasp柯于旺 原创文章,如需转载请联系本人。

  • 相关阅读:
    luogu P3959 宝藏
    hdu4035 Maze
    [hdu2899]Strange fuction
    luogu4407 [JSOI2009]电子字典 字符串hash + hash表
    SPOJ6717 Two Paths 树形dp
    luogu4595 [COCI2011-2012#5] POPLOCAVANJE 后缀自动机
    后缀数组
    luoguP1659 [国际集训队]拉拉队排练 manacher算法
    luoguP4555 [国家集训队]最长双回文串 manacher算法
    CF17E Palisection 差分+manacher算法
  • 原文地址:https://www.cnblogs.com/NoMasp/p/4786054.html
Copyright © 2011-2022 走看看