用通用函数代替普通函数 [英] Replacing an ordinary function with a generic function

查看:105
本文介绍了用通用函数代替普通函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用诸如elt,nth和mapcar之类的名称与我正在开发原型的新数据结构一起使用,但是这些名称指定了普通函数,因此,我认为需要将其重新定义为泛型函数.

I'd like to use names such as elt, nth and mapcar with a new data structure that I am prototyping, but these names designate ordinary functions and so, I think, would need to be redefined as generic functions.

重新定义这些名称大概是不好的形式吗?

Presumably it's bad form to redefine these names?

有没有办法告诉defgeneric不要产生程序错误并继续进行功能绑定的替换?

Is there a way to tell defgeneric not to generate a program error and to go ahead and replace the function binding?

这些不是通用函数还是历史悠久,是否有充分的理由?

Is there a good reason for these not being generic functions or is just historic?

请问这里有什么公认的智慧和最佳实践?

What's the considered wisdom and best practice here please?

推荐答案

如果您使用的是SBCL或ABCL,并且与ANSI兼容性无关,则可以研究可扩展序列:

If you are using SBCL or ABCL, and aren't concerned with ANSI compliance, you could investigate Extensible Sequences:

http://www.sbcl.org/manual/#Extensible-Sequences

http://www.doc.gold.ac.uk/〜mas01cr/papers/ilc2007/sequences-20070301.pdf

...您无法在COMMON-LISP程序包中重新定义功能,但是可以创建一个新程序包并隐藏要重新定义的功能的导入.

...you can't redefine functions in the COMMON-LISP package, but you could create a new package and shadow the imports of the functions you want to redefine.

这篇关于用通用函数代替普通函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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