为什么在《 The Little Schemer》中所有lambda? [英] Why all the lambdas in The Little Schemer?

查看:83
本文介绍了为什么在《 The Little Schemer》中所有lambda?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从SICP学习了一些Scheme之后,我开始阅读《 The Little Schemer》(我觉得很有趣),并且完成了大约四分之一.我注意到,无需使用lambda即可编写许多(大多数?全部?)解决方案,而The Little Schemer 始终使用它们.例如,第一个定义是

After learning a bit of Scheme from SICP, I started reading The Little Schemer (which I find quite entertaining) and am about one fourth done. I noticed that I can write many (most? all?) solutions without using lambda whereas The Little Schemer always uses them. For example, the very first definition is

(define atom?
  (lambda (x)
    (and (not (pair? x)) (not (null? x)))))

除非我没有记错,否则可以将其写为更简单

which, unless I am mistaken, can be written more simply as

(define (atom? x) 
   (and (not (pair? x)) (not (null? x))))

如果我编写无lambda的解决方案,我会错过一些基本的东西吗?

Am I missing something fundamental if I write lambda-less solutions?

推荐答案

最初,define具有一种语法,用于将变量设置为值.那就是这种古老(和永恒)的书中使用的风格.后来,define有了不同的语法作为快捷方式,这就是您正在使用的语法.

Originally, define had a single syntax, to set a variable to a value. That's the style used in such old (and timeless) books. Later on, define got a different syntax as a shortcut, which is the one you're using.

只是为了好玩,在您的Scheme库中进行搜索,您可能会发现一个宏,该宏会将非lambda形式扩展为旧的lambda形式.

Just for fun, search on your Scheme libraries, you might find a macro that expands the non-lambda form into the old lambda-heavy one.

这篇关于为什么在《 The Little Schemer》中所有lambda?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆