无参数(和)返回t [英] No-argument (and) returns t

查看:150
本文介绍了无参数(和)返回t的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CL和Scheme定义(和)以返回 t (或 #t

Both CL and Scheme define (and) to return t (or #t) with no arguments.

我试图理解这个的理由。我天真的假设是一个空集是假的,传递零参数感觉像没有什么可以是真的传递。

I'm trying to understand the rationale for this. My naive assumption is that an empty set is false, and passing in zero arguments feels like passing in nothing that can be true.

编辑:clojure遵循相同的约定。我必须缺少一些基本的Lisp假设。

clojure follows the same convention. I must be missing some basic Lisp assumption.

推荐答案

空产品是1.原因是1是一个中性元素 *

The empty product is 1. The reason is that 1 is a neutral element for *.

如果你有2和3的乘积然后乘以无产品得到2 * 3 * 1 = 6.我们可以写

If you have the product of 2 and 3 and then multiply by the product of nothing, you will get 2*3*1 = 6. We can write

  (product (product 2 3) (product)) 
= (product 6 1) 
= 6

c>和

The same computation with and:

  (and (and #t #t) (and)) 
= (and #t ?) 
= #t

code>(和)以给出不会影响结果的值
答案是 #t ,因为 #t 是一个中性元素。

We want the empty (and) to give a value ? that doesn't affect the result. The answer is #t since #t is a neutral element.

(and x #t) = x   for all boolean x

这篇关于无参数(和)返回t的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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