Trial solution to the SiC exercise (1.5)

Source: Internet
Author: User
 

========================================================== ====================================
;
; Structure and Interpretation of Computer Programs
; (Trial answer to excercises)
;
The construction and interpretation of computer programs (exercises)
;
; Created: code17 02/24/05
; Modified:
; (The content can be reproduced without changing the content)
; ========================================================== ====================================

; SICP No.1.5
; This topic is entitled Understanding questions

; (Define (p ))
;;
; Is equivalent to defining an infinite recursive function p, p as the operator, with 0 operant as the parameter. By definition
; It can be seen that (p) will be evalute as (p), and (p) and then evaluate as (p). Endless.
; P itself as a procedure is no problem, we allow defining recursive functions, but when p acts on operant
;, (P) is problematic because its evaluation is infinitely recursive. Therefore, in scheme,
; () Is not only a priority control tool, but a semantic control tool that cannot be ignored. P is a function,
; While (p) is the return value after FUNCTION p acts on its parameters (0.
;;
; Test-it:
; Welcome to MzScheme version 209, Copyright (c) 2004 PLT Scheme, Inc.
;> (Define (p ))
;> P
; # <Procedure: p>
;> (P)
; The interaction interpreter has no response here

; (Define (test x y)
; (If (= x 0)
; 0
; Y ))
; (Test 0 (p ))
;;
; Therefore, the results of the test function in the evaluation sequence of different principles can be easily inferred. In
; Under the normal-order evaluation principle, only when the value of an expression is required
; Evaluation, (test 0 (p) will be evaluate as (if (= 0 0) 0 (p )),
; Because the judgment condition is true, the final expression evaluate is 0, and the (p) value does not need to be calculated.
; To avoid infinite recursion; and under the applicative-order principle, all
; Operants must evaluate before substitution, so (p) calculation cannot be avoided, and the result is infinite recursion.
;;
; Test-it:
;> (Test 0 (p ))
; The interaction interpreter loses response here because scheme uses applicative-order evaluation

; If we define
; (Define (p)
; Is another meaning, it defines a function with 0 operant p, when it acts on its operant
;, The return value is set to itself, so that (p) is evaluate to p, then (p) is evaluate
; (P) and then evaluate as p, then (p ))))))
;;
; Test-it:
;> (Define (p)
;> P
; # <Procedure: p>
;> (P)
; # <Procedure: p>
;> (P ))
; # <Procedure: p>
;> )))))))))))))))) )))))))
; # <Procedure: p>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.