如何在 YAML 中指定范围?
我可以表达
第三页是扉页
第 3 页是YAML 中的
title: 3
下面呢?
第 10 至 15 页包含第 1 章
一种方法是
chapter 1: [10, 11, 12, 13, 14, 15]
我更喜欢在这里给出一个范围。 YAML 中有类似的东西吗?
chapter 1: (10..15)
** 更新 **
如果 YAML 中没有范围之类的东西,以下是我的替代方案
chapter 1:
start page: 10
end page: 15
I can express
3rd page is the title page
in YAML
title: 3
What about the following?
Pages 10 to 15 contains chapter 1
One way is
chapter 1: [10, 11, 12, 13, 14, 15]
I would prefer a range here. Is there anything like that in YAML?
chapter 1: (10..15)
** Update **
The following would be my alternative if there is no such thing as range in YAML
chapter 1:
start page: 10
end page: 15
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在 YAML 中没有直接指定范围的方法,但某些 YAML 可以存储序列化对象,例如在 Ruby 中:
看这里
There is not direct way to specify ranges in YAML, but some YAML can store serialized objects, for example in Ruby:
Look here
范围是特定于应用的。以下内容对于某些应用程序可能有意义:
-1 .. Q
a .. Щ
23 .. -23.45
1 .. 12:01:14 (两者都是 YAML 中的整数!)
但是 ruby 方式也不清楚,因为它不说出是否包含最终值:10 .. 15
(您只谈论整数范围吗?)
Range is application specific. The following may be meaningful for some applications:
-1 .. Q
a .. Щ
23 .. -23.45
1 .. 12:01:14 (both are integers in YAML !)
But the ruby way is also unclear since it does not say whether the end values are included or not: 10 .. 15
(Are you only talking about ranges of integers ?)
安德烈是对的——不存在基本范围之类的东西。范围可以在全序数据类型之上定义。 YAML 甚至不知道排序的概念,因此在 YAML 中讨论范围是没有意义的。 YAML 只知道节点类型的概念、相等的概念以及节点之间的一些预定义类型的链接。顺便说一句,我不知道任何其他本身支持范围的数据序列化语言(JSON、XML、CSV、Hessian、Protocol Buffers...)。
Andrey is right - there is no such thing as a basic range. Ranges can be defined on top of totally ordered data types. YAML does not even know the concept of ordering so it makes no sense to talk about ranges in YAML. YAML only knows the concept of node types, the concept of equality, and some predefined kinds of links between nodes. By the way I don't know any other data serialization lange (JSON, XML, CSV, Hessian, Protocol Buffers...) that natively supports ranges.
实际上,对于像这样的范围
可以使用数组(元素 [0] 或偶数元素 - 起始页,元素 [1] 或奇数元素 - 结束页):
如果 Chapter2第 21 页有中断
Actually, for ranges like
is possible to use arrays (element [0] or even elements - start page, element [1] or odd elements - end page):
if chapter2 has break on page 21