Perl 6 中的 Cool

class Cool - 可以作为字符串或数字互换的值

class Cool is Any { }

我们看下官方文档给出的英文解释:

Value that can be treated as a string or number interchangeably

Cool, 也称为 Convenient OO Loop,是字符串、数字和其他内置类的基类,大多数你可以互换使用。

Cool 中的方法强迫调用者到一个更具体的类型,然后调用该类型的相同的方法。 例如,IntStr 都继承自 Cool,并且在 Int 上调用 substr 方法会首先将整数转换为 Str

123.substr(1, 1);   # '2', same as 123.Str.substr(1, 1)

下面的内置类型继承自 Cool: ArrayBoolComplexCoolDurationMapFatRatHashInstantIntListMatchNilNumRangeSeqStashStr

下表总结了 Cool 所提供的方法,以及它们所被强制到的类型:

method coercion type
abs Numeric
conj Numeric
sqrt Numeric
sign Real
rand Numeric
sin Numeric
asin Numeric
cos Numeric
acos Numeric
tan Numeric
tanh Numeric
atan Numeric
atan2 Numeric
atanh Numeric
sec Numeric
asec Numeric
cosec Numeric
acosec Numeric
cotan Numeric
cotanh Numeric
acotan Numeric
sinh Numeric
asinh Numeric
cosh Numeric
acosh Numeric
sech Numeric
asech Numeric
cosech Numeric
acosech Numeric
acotanh Numeric
cis Numeric
log Numeric
exp Numeric
roots Numeric
log10 Numeric
unpolar Numeric
round Numeric
floor Numeric
ceiling Numeric
truncate Numeric
chr Int
ord Str
chars Str
fmt Str
uniname Str
uninames Seq
unival Str
univals Str
uniprop Str
uniprop-int Str
uniprop-str Str
uniprop-bool Str
unimatch Str
uc Str
lc Str
fc Str
tc Str
tclc Str
flip Str
trans Str
index Str
rindex Str
ords Str
split Str
match Str
comb Str
subst Str
sprintf Str
printf Str
samecase Str
trim Str
trim-leading Str
trim-trailing Str
EVAL Str
chomp Str
chop Str
codes Str
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1. Java基础部分 基础部分的顺序:基本语法,类相关的语法,内部类的语法,继承相关的语法,异常的语法,线程的语...
    子非鱼_t_阅读 31,934评论 18 399
  • importUIKit classViewController:UITabBarController{ enumD...
    明哥_Young阅读 9,442评论 1 10
  • 在经过一次没有准备的面试后,发现自己虽然写了两年的android代码,基础知识却忘的差不多了。这是程序员的大忌,没...
    猿来如痴阅读 8,003评论 3 10
  • 初来乍到,引曾经语文先生的一席话作为开场 今天是西方的圣诞节,顾名思义,是圣人诞生之日为节。西方圣人为耶稣,今日为...
    藏茶阅读 1,007评论 0 0
  • 风 文/阿馨 我已不能 掂出你的轻重分量 明确你前行的方向 你时左时右 时前时后 时而舒缓 时而疯狂 有时如温柔的...
    诗意的栖居_b130阅读 2,350评论 4 12