以下函数定义各自在编译时使用 {{:advanced}} 编译器引发 {{ERROR: JSC_DUPLICATEPARAM. 解析错误。重复参数名称 ""}} 错误。
`
(defn causes-duplicate-param [{_ :foo}]
(reify
Object
(a-function [-]
(fn [] "arbitrary function inside a-function body"))))
(defn causes-duplicate-param [{- :foo}]
(reify
Object
(a-function [_]
(fn [] "arbitrary function inside a-function body"))))
`
它们分别生成
`
duplicate_param_name_demo.core.t_duplicate_param_name_demo$core1601.prototype.a_function = ((function (map1599,map1599$1,_){
return (function (){
var self = this;
var = this;
return ((function (,map1599,map1599$1,){
return (function (){
return "函数体内的任意函数";
});
;})(,map1599,map1599_$1,))
});})(map1599,map1599$1,_))
;
duplicate_param_name_demo.core.t_duplicate_param_name_demo$core1612.prototype.a_function = ((function (map1610,map1610$1,_){
return (function (){
var self = this;
var = this;
return ((function (,map1610,map1610$1,){
return (function (){
return "函数体内的任意函数";
});
;})(,map1610,map1610_$1,))
});})(map1610,map1610_$1,))
;
`
(注意每个中的第 5 行都出现了重复的 {{_}} 参数。)
以下则没有
`
(defn causes-duplicate-param [{- :foo}]
(reify
Object
(a-function [-]
(fn [] "arbitrary function inside a-function body"))))
(defn causes-duplicate-param [{_ :foo}]
(reify
Object
(a-function [_]
(fn [] "arbitrary function inside a-function body"))))
`
它们生成
`
duplicate_param_name_demo.core.t_duplicate_param_name_demo$core1601.prototype.a_function = ((function (map1599,map1599$1,_){
return (function (){
var self_ = this;
var $1 = this;
return ((function (_$1,map1599,map1599_$1,){
return (function (){
return "函数体内的任意函数";
});
;})(_$1,map1599,map1599_$1,))
});})(map1599,map1599_$1,))
;
duplicate_param_name_demo.core.t_duplicate_param_name_demo$core1612.prototype.a_function = ((function (map1610,map1610$1,_){
return (function (){
var self_ = this;
var $1 = this;
return ((function (_$1,map1610,map1610_$1,){
return (function (){
return "函数体内的任意函数";
});
;})(_$1,map1610,map1610_$1,))
});})(map1610,map1610_$1,))
;
`
(注意其中的一个 {{_}} 参数已变为 {{___$1}}。)
虽然我没有详细查看编译器代码,但我猜测编译器会在冲突时将 {{_}} 转义为 {{__$1}},也将 {{-}} 转义为 {{_}},但它没有注意到当 ClojureScript 符号不同时的冲突。