哪种语言支持创建新数据类型? [英] Which languages support new data types creation ?

查看:95
本文介绍了哪种语言支持创建新数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



哪种语言可以创建自己的新数据类型?



喜欢#define在C中,用于替换丢失的布尔类型等。



非常感谢

Hi guys,

Which language can create own new data types ?

Like #define in C ,for replacing missing boolean type etc.

Much thanks

推荐答案

#define无法创建新类型:它允许您定义预编译宏和文本替换。这不是一回事。

你在C中创建新类型的最接近的是 typedef struct ,但是现在它很差除了变量之外,它不支持任何其他内容。大多数现代语言支持正确的对象定义,其中包括至少方法。



我不认为任何人都会列出所有允许的语言编码器定义新的数据类型(对象与否)因为没有人知道所有语言 - 我们都知道所有语言的子集 - 你可以在COBOL甚至汇编代码中实现类似结构的元素。



这是一个愚蠢的问题!
#define does not create new types: it allows you to define pre-compilation macros and text replacements. This is not the same thing.
The closest you could get to new type creating in C is typedef struct, but it's pretty poor these days as it doesn't support anything other than variables. Most modern languages support "proper" object definition, which include methods at teh very least.

I don;t think anyone is going to list all the languages that allow the coder to define new datatypes (object or not) since nobody knows all languages - we all know a subset of all languages - and you can implement structure-like elements in COBOL and even assembler code.

It's a silly question!


这是一个绝对适得其反的问题。可能你不知道世界上有多少种语言。没有人会为你计算它们,只是因为在这个无用的练习中会出现一些新的语言。



另外,你不知道 #define 是。它永远不会定义类型,即使在通过 #define 中引入的定义的使用(实际上是宏扩展)定义类型的情况下也是如此。这是预处理器宏定义的构造。换句话说,编译的程序中不存在 #define 行的内容。请参阅:

http://en.wikipedia.org/wiki/C_preprocessor [< a href =http://en.wikipedia.org/wiki/C_preprocessortarget =_ blanktitle =New Window> ^ ]。



但C语言当然允许您创建类型: http://en.wikipedia.org/wiki/Struct_ %28C_programming_language%29 [ ^ ] 。



请注意,在其他语言中,您不应混淆创建类型与类型别名类型重命名。如果创建可以使用的新名称而不是原始类型名称,则不会创建新类型。它支持类型身份(类似 typeof )的语言或系统,原始和新类型将被识别为相同类型。



另请参阅:

http:// en。 wikipedia.org/wiki/Type_safety [ ^ ],

http://en.wikipedia.org/wiki/Type_system [ ^ ],

http://en.wikipedia.org/wiki/Type_theory [ ^ ]。



-SA
This is the absolutely counter-productive question. Probably you have no clue how many languages are there in the world. No one is going to count them for you, just because during this useless exercise some new language can emerge.

Also, you have no clue what "#define" is. It never defines types, even in the cases when the type is defined through the use (macro expansion, in fact) of the definition introduced in "#define". This is a construct for pre-processor macro definition. In other words, the content of "#define" lines does not exist in the compiled program. Please see:
http://en.wikipedia.org/wiki/C_preprocessor[^].

But C language certainly allows you creation of types: http://en.wikipedia.org/wiki/Struct_%28C_programming_language%29[^].

Note that, in other languages, you should not mix-up creation of a type with creation of type alias or type renaming. If you create a new name which can be used instead of original type name, you don't create a new type. It languages or systems supporting type identity (something like typeof) the original and "new" types would be recognized as the same type.

See also:
http://en.wikipedia.org/wiki/Type_safety[^],
http://en.wikipedia.org/wiki/Type_system[^],
http://en.wikipedia.org/wiki/Type_theory[^].

—SA

这篇关于哪种语言支持创建新数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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