Clojure - 测试函数表达式的相等性? [英] Clojure - test for equality of function expression?

查看:140
本文介绍了Clojure - 测试函数表达式的相等性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有以下clojure函数:

 (defn a [x](* xx))

(def b(fn [x](* xx)))

(def c(eval(read-string(defn d [x](* xx)))) )

有一种方法来测试函数表达式的等同性 - >

 (eqls ab)


$ b b

返回true?

解决方案

我同意上述关于Clojure没有内置能力两个函数的等价性,并且已经证明你不能测试程序功能(也称为黑盒测试),以确定由于停止问题导致的相等性(除非输入集是有限和定义的)。



我想指出,即使它们具有不同的形式(不同的字节代码),也可以代数确定两个函数的等价性。



代数相等的证明方法是在20世纪30年代由Alonzo Church开发的,并且被称为λ微积分的β减少。这种方法肯定适用于你的问题中的简单形式(这也将产生相同的字节代码),也适用于更复杂的形式,将产生不同的字节代码。


Suppose I have the following clojure functions:

(defn a [x] (* x x))

(def b (fn [x] (* x x)))

(def c (eval (read-string "(defn d [x] (* x x))")))

Is there a way to test for the equality of the function expression - some equivalent of

(eqls a b)

returns true?

解决方案

I agree with the above answers in regards to Clojure not having a built in ability to determine the equivalence of two functions and that it has been proven that you can not test programs functionally (also known as black box testing) to determine equality due to the halting problem (unless the input set is finite and defined).

I would like to point out that it is possible to algebraically determine the equivalence of two functions, even if they have different forms (different byte code).

The method for proving the equivalence algebraically was developed in the 1930's by Alonzo Church and is know as beta reduction in Lambda Calculus. This method is certainly applicable to the simple forms in your question (which would also yield the same byte code) and also for more complex forms that would yield different byte codes.

这篇关于Clojure - 测试函数表达式的相等性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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