Perl 是弱类型还是强类型? [英] Is Perl weakly or strongly typed?

查看:49
本文介绍了Perl 是弱类型还是强类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在从 learn.perl.org 学习 Perl 5,我对它的类型系统很好奇.我看到有关 Perl 是弱类型还是强类型以及它也是动态类型的混合信息.维基百科声明它也支持鸭子类型.

I am currently learning Perl 5 from learn.perl.org and I am curious about its typing system. I see mixed information about Perl being weakly or strongly typed, and that it is also dynamically typed. Wikipedia states that it also supports duck typing.

谁能确认它是弱类型还是强类型?

Can anyone confirm its weakly or strongly typed nature?

推荐答案

我看到有关 Perl 弱类型或强类型的混合信息

这并不奇怪,因为关于 C 是强类型语言还是弱类型语言也存在相互矛盾的信息.

That's no surprise given that there is also conflicting information as to whether C is a strongly-typed or weakly-typed language.

  • 静态但类型语言的一个例子是 C.[来源]

  • An example for a statically, but weakly typed language is C. [source]

C 是强烈类型的... [来源]

C is strongly typed... [source]

这适用于类型的语言,例如 C.[来源]

This works fine in weakly typed languages such as C. [source]

LISP 引擎...本身通常用类型语言编写,例如 C... [来源]

LISP engines ... are themselves generally written in strongly typed languages like C... [source]

在诸如 C 之类的类型语言中,... [来源]

In a weakly typed language such as C, ... [source]

类型:强烈类型:(C、Algol、Fortran)[来源]

TYPE: strongly typed: (C, Algol, Fortran) [source]

Mark J Dominus 编译以上列表,发现对于强类型的含义有八个不兼容的定义.

Mark J Dominus compiled the above list, and discovered there are eight incompatible definitions for what it means to be strongly-typed.

  1. 如果类型注释与变量名称相关联,而不是与值相关联,则语言是强类型的.如果类型附加到值,则它是弱类型的.

  1. A language is strongly typed if type annotations are associated with variable names, rather than with values. If types are attached to values, it is weakly typed.

如果一种语言包含编译时类型约束违规检查,那么它就是强类型语言.如果检查被推迟到运行时,它是弱类型的.

A language is strongly typed if it contains compile-time checks for type constraint violations. If checking is deferred to run time, it is weakly typed.

如果一种语言包含对类型约束违规的编译或运行时检查,则该语言是强类型的.如果不做检查,就是弱类型.

A language is strongly typed if it contains compile or run-time checks for type constraint violations. If no checking is done, it is weakly typed.

如果禁止不同类型之间的转换,则该语言是强类型的.如果允许这种转换,则它是弱类型的.

A language is strongly typed if conversions between different types are forbidden. If such conversions are allowed, it is weakly typed.

如果必须明确指示不同类型之间的转换,则语言是强类型的.如果执行隐式转换,则为弱类型.

A language is strongly typed if conversions between different types must be indicated explicitly. If implicit conversions are performed, it is weakly typed.

如果没有语言级别的方法来禁用或规避类型系统,则该语言是强类型的.如果有强制转换或其他类型规避机制,则为弱类型.

A language is strongly typed if there is no language-level way to disable or evade the type system. If there are casts or other type-evasive mechansisms, it is weakly typed.

如果一种语言具有带有复合类型的复杂、细粒度的类型系统,那么它就是强类型的.如果它只有几种类型,或者只有标量类型,则它是弱类型的.

A language is strongly typed if it has a complex, fine-grained type system with compound types. If it has only a few types, or only scalar types, it is weakly typed.

如果一种语言的数据对象的类型是固定的并且在对象的生命周期内不会变化,则该语言是强类型的.如果数据的类型可以改变,则该语言是弱类型的.

A language is strongly typed if the type of its data objects is fixed and does not vary over the lifetime of the object. If the type of a datum can change, the language is weakly typed.

这表明强类型"和弱类型"是毫无意义的短语.因此,本答案的其余部分和所有其他答案实际上只是对您所问内容的猜测.

This goes to show that "strongly-typed" and "weakly-typed" are meaningless phrases. As such, the rest of this answer and all other answers are really just guesses at what you are asking.

Perl 是弱类型还是强类型?

它有强类型(标量、数组、散列等)和弱类型(字符串、浮点数、有符号整数、无符号整数、引用等).

It has both strong types (scalar, array, hash, etc) and weak types (string, floating point number, signed integer, unsigned integer, references, etc).

这是基于上面列表中的定义 #1、#2、#4、#5 和 #6.

This is based on definitions #1, #2, #4, #5 and #6 from the above list.

维基百科声明它也支持鸭子输入.

方法调用确实使用了动态绑定(鸭子输入).

Method calls do indeed utilize dynamic binding (duck typing).

这意味着$o->method调用的方法是基于$o的当前值,而不是与$o<相关联的/code> 本身.

This means the method called by $o->method is based on the current value of $o, rather than one associated with $o itself.

据我所知,这个定义是明确的.

As far as I know, the definition for this is unambiguous.

这篇关于Perl 是弱类型还是强类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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