clojure-本地替代运算符(例如"+","*"等)的正确方法 [英] clojure -- correct way to locally override operators such as "+", "*", etc

查看:85
本文介绍了clojure-本地替代运算符(例如"+","*"等)的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

覆盖"+"之类的方法的正确方法是什么?现在我有

What is the correct way to override a method like "+"? Right now I have

(defn- + [x y] (replacement x y))

但这会在命令行上显示警告.

but this results in warnings on the command line.

WARNING: + already refers to: #'clojure.core/+ in namespace: <MY-NAMESPACE>, being replaced by #'<MY-NAMESPACE>/+

推荐答案

您需要排除由核心导入的功能:

You need to exclude the functions that are imported by core:

 (ns your-ns
   (:refer-clojure :exclude [+ ...]))

 (defn + ...)

这篇关于clojure-本地替代运算符(例如"+","*"等)的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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