perhaps? 2010-05-31 11:04 采纳率: 100%
浏览 205
已采纳

浪达计划的意义何在?

I am learning scheme. I know how to use both lambda and let expressions.

However I'm struggling to figure out what the point is of using lambda. Can't you do everything with let that you can with lambda?

It would be especially helpful to see an example of a situation where a lambda expression is a better choice than let.

One other thing - are there also situations where let is more useful than lambda? If so such an example would be nice as well.

Edit: I'm also interested in contrasting define and lambda, as they seem to perform similar tasks.


Update:

Thanks for the help everyone. I did some more looking into lambda/let/define after reading your answers, and now understand it a lot better.

I came accross an excellent example of cool lambda useage - returning anonymous functions from procedures. For example, the procedure operateTwice below returns an anonymous function that is based on parameters passed in to the procedure:

(define operateTwice
  (lambda (op1 op2)
    (lambda (x y)
      (op2 (op1 x y) y))))

((operateTwice * +) 2 3) ;equivalent to: (+ (* 2 3) 3), or in standard notation 2*3+3

Output:

9

转载于:https://stackoverflow.com/questions/2943072/whats-the-point-of-lambda-in-scheme

  • 写回答

6条回答 默认 最新

  • 笑故挽风 2010-05-31 11:15
    关注

    A let is a lambda.

    E.g.

    (let ((x 1))
      body)
    

    can be translated into

    ((lambda (x) body) 1)
    

    Furthermore, in Scheme all control and environment structures can be represented by lambda expressions and applications of lambdas.

    So, lambda is strictly more powerful than let and forms the basis of many of the interesting constructs found in Scheme.

    Concerning define and lambda, a top-level define adds a binding to the top-level environment.

    When you write

    (define (f x)
      body)
    

    you are really saying

    (define f (lambda (x) body))
    

    Nested defines are translated into letrec, which can be rewritten using lambdas as well.

    So, again, a lot of Scheme constructs can be translated into something using lambda, and therefore it is really worthwile that you understand lambda well.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 被蓝屏搞吐了,有偿求帮解答,Ai回复直接拉黑
  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角