zoukankan      html  css  js  c++  java
  • let区别(关于racket和r5rs)

    R5RS is the Revised5 Report on the Algorithmic Language Scheme.参考http://www.schemers.org/Documents/Standards/R5RS/

    racket let 用法:

     

    (let ([id val-expr] ...) body ...+)

    (let proc-id ([id init-expr] ...) body ...+)
    The first form evaluates the val-exprs left-to-right, creates a newlocation for each id, and places the values into the locations. It then evaluates the bodys, in which the ids are bound. The last bodyexpression is in tail position with respect to the let form. The ids must be distinct according to bound-identifier=?.

    Examples:

    (let ([x 5]) x)

    5

    (let ([x 5])
        (let ([x 2]
              [y x])
          (list y x)))

    '(5 2)

    The second form evaluates the init-exprs; the resulting values become arguments in an application of a procedure (lambda (id ...) body ...+), where proc-id is bound within the bodys to the procedure itself.

    Example:

    (let fac ([n 10])
        (if (zero? n)
            1
            (* n (fac (sub1 n)))))

    3628800

    syntax

    (let* ([id val-expr] ...) body ...+)

    Like let, but evaluates the val-exprs one by one, creating a locationfor each id as soon as the value is available. The ids are bound in the remaining val-exprs as well as the bodys, and the ids need not be distinct; later bindings shadow earlier bindings.

    Example:

    (let* ([x 1]
             [y (+ x 1)])
        (list y x))

    '(2 1)

    r5rs:

    library syntax:  (let <bindings> <body>) 

    Syntax: <Bindings> should have the form ((<variable1> <init1>) ...),

    where each <init> is an expression, and <body> should be a sequence of one or more expressions. It is an error for a <variable> to appear more than once in the list of variables being bound.

    Semantics: The <init>s are evaluated in the current environment (in some unspecified order), the <variable>s are bound to fresh locations holding the results, the <body> is evaluated in the extended environment, and the value(s) of the last expression of <body> is(are) returned. Each binding of a <variable> has <body> as its region.

    (let ((x 2) (y 3))
      (* x y))                              ===>  6

    (let ((x 2) (y 3))
      (let ((x 7)
            (z (+ x y)))
        (* z x)))                           ===>  35

    See also named let, section 4.2.4.

    library syntax:  (let* <bindings> <body>) 

    Syntax: <Bindings> should have the form ((<variable1> <init1>) ...),

    and <body> should be a sequence of one or more expressions.

    Semantics: Let* is similar to let, but the bindings are performed sequentially from left to right, and the region of a binding indicated by(<variable> <init>) is that part of the let* expression to the right of the binding. Thus the second binding is done in an environment in which the first binding is visible, and so on.

    (let ((x 2) (y 3))
      (let* ((x 7)
             (z (+ x y)))
        (* z x)))                     ===>  70

  • 相关阅读:
    独立性检验|适应性检验|卡方检验|离散型数据|连续型数据
    双因子方差分析|adjusted R|强度|SSA|SSE|SST|
    发明人|申请人|专利权人|完全民事能力|谁主张谁证明|新颖性|创造性|实用性|先申请制
    方差分析|重复|指标|因素|处理效应|实验误差|实验设计可避免的误差|一般线性|广义线性
    字符数组1
    四舍五入输出数字
    如何输出0001, 0002, 0003... 这样的数
    shell scripting Python
    [C&Python]9x9乘法口诀打印
    [pointer]调用函数找出一维数组中的最值,
  • 原文地址:https://www.cnblogs.com/youxin/p/3417395.html
Copyright © 2011-2022 走看看