Ada 中的自定义“图像"属性? [英] Custom 'image attribute in Ada?
问题描述
所以我有件事.
type Thing is new record
...elements...
end record;
我有一个字符串化它的函数.
I have a function which stringifies it.
function ToString(t: Thing) returns string;
我希望能够告诉 Ada 将此函数用于 Thing'image
,这样我的库的用户就不必考虑他们使用的是内置类型还是一件事.
I would like to be able to tell Ada to use this function for Thing'image
, so that users of my library don't have to think about whether they're using a builtin type or a Thing.
但是,明显的语法:
for Thing'image use ToString;
...不起作用.
有没有办法做到这一点?
Is there a way to do this?
推荐答案
我不知道为什么语言不支持这个,我不知道是否有人提出过正式的建议,它应该(一个Ada 问题或 AI).有点相关的AI12-0020(Ada 2012 的第 20 届 AI)包括我认为我们拒绝它的原因不是技术原因,而是重要性".
I don’t know why the language doesn’t support this, and I don’t know whether anyone has ever raised a formal proposal that it should (an Ada Issue or AI). The somewhat-related AI12-0020 (the 20th AI for Ada 2012) includes the remark "I don't think we rejected it for technical reasons as much as importance".
您可以看到为什么 Ada Rapporteur Group 可能认为这相对不重要:您总是可以声明一个 Image
函数;之间的区别
You can see why the Ada Rapporteur Group might think this was relatively unimportant: you can always declare an Image
function; the difference between
Pkg.Image (V);
和
Pkg.Typ’Image (V);
不是很大.
这篇关于Ada 中的自定义“图像"属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!