DateTime当我在序列运算符 ( ) 的两侧使用两个对象时...,Raku 报告说No such method 'succ' for invocant of type 'DateTime'. Did you mean any of these: 'sum', 'utc'?
DateTime.new("2022-03-26") ... DateTime.new("2022-03-28")
Run Code Online (Sandbox Code Playgroud)
然而,当运算符的左侧...是一个Date对象,右侧也是一个DateTime对象时,就会导致无限循环:
.say for Date.new("2022-03-26") ... DateTime.new("2022-03-28");
.say for Date.new("2022-03-26") ... DateTime.new("2022-03-18");
Run Code Online (Sandbox Code Playgroud)
上述语法有效吗?是否应该报告错误?
作为比较,以下代码运行良好:
.say for Date.new("2022-03-26") .. DateTime.new("2022-03-28")
.say for Date.new("2022-03-26") .. Date.new("2022-03-28")
Run Code Online (Sandbox Code Playgroud)
输出:
2022-03-26
2022-03-27
2022-03-28
Run Code Online (Sandbox Code Playgroud) 在Python中,unpack可以将十六进制字符串转换为IEEE754浮点数:
import struct
print(struct.unpack('<f', bytes.fromhex("00000042"))[0]) # 32.0
Run Code Online (Sandbox Code Playgroud)
<表示 LITTLE ENDIAN 字节顺序,f表示 Float 格式。
如何使用 Raku 将十六进制字符串转换为 IEEE754 浮点数?
在 Python 中解包二进制数据:
import struct
bytesarray = "01234567".encode('utf-8')
# Return a new Struct object which writes and reads binary data according to the format string.
s = struct.Struct('=BI3s')
s = s.unpack(bytesarray) # Output: (48, 875770417, b'567')
Run Code Online (Sandbox Code Playgroud)
Raku 有类似 Python 的 Struct 的功能吗?如何根据 Raku 中的格式字符串解压缩二进制数据?
在我看来,有效的Match 对象不是空的或未定义的:
say Match.new(:orig("20230213112803"), :from(4), :pos(6)).elems; # 0
say Match.new(:orig("20230213112803"), :from(4), :pos(6)).chars; # 2
say Match.new(:orig("20230213112803"), :from(4), :pos(6)).defined; # True
Run Code Online (Sandbox Code Playgroud)
但以下带有循环输出Match中的对象的尖头块:forNil
for Match.new(:orig("20230213112803"), :from(4), :pos(6)) -> $m {
say ~$m
}
# OUTPUT: Nil
Run Code Online (Sandbox Code Playgroud)
但该given声明输出了我所期望的:
given Match.new(:orig("20230213112803"), :from(4), :pos(6)) -> $m {
say ~$m
}
# OUTPUT: 02
Run Code Online (Sandbox Code Playgroud)
是不是有一些空的或未定义的东西阻止了for循环的执行?
for "a" -> $m { say $m } # a
for [] -> $m { say $m } # Nil
for …Run Code Online (Sandbox Code Playgroud) 我在doc.perl6.org中看到了触发器的使用,请参阅下面的代码:
my $excerpt = q:to/END/;
Here's some unimportant text.
=begin code
This code block is what we're after.
We'll use 'ff' to get it.
=end code
More unimportant text.
=begin code
I want this line.
and this line as well.
HaHa
=end code
More unimport text.
=begin code
Let's to go home.
=end code
END
my @codelines = gather for $excerpt.lines {
take $_ if "=begin code" ff "=end code"
}
# this will print four lines, starting …Run Code Online (Sandbox Code Playgroud) 在Python中,我可以像这样拼接字符串:
solo = A quick brown fox jump over the lazy dog
solo[3:5]
Run Code Online (Sandbox Code Playgroud)
我知道substr并且comb已经足够了,我想知道它是否可行,但是.我应该使用角色来做到这一点吗?
我想.sql使用Perl 6 Grammar 来删除文件,我想知道我在解析时是否可以跳过一些不相关的行?
例如:我想在下面的文本中跳过块外的DROP行,/*!....!*/行,--行和空格CREATE TABLE.
也就是说,我想要专注于CREATE TABLE块:
DROP TABLE IF EXISTS `abcd`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `abcd` (
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'app_id',
`username` varchar(255) DEFAULT NULL COMMENT 'username',
`url` varbinary(255) DEFAULT NULL COMMENT 'url',
PRIMARY KEY (`id`),
UNIQUE KEY `NewIndex1` (`username`)
) ENGINE=InnoDB AUTO_INCREMENT=954 DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- …Run Code Online (Sandbox Code Playgroud)