如何在 YAML 中指定范围?

发布于 2024-09-11 10:30:16 字数 468 浏览 2 评论 0原文

我可以表达

第三页是扉页

第 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

老旧海报 2024-09-18 10:30:16

在 YAML 中没有直接指定范围的方法,但某些 YAML 可以存储序列化对象,例如在 Ruby 中:

...
normal range: !ruby/range 10..20 
exclusive range: !ruby/range 11...20 
negative range: !ruby/range -1..-5 
...

看这里

There is not direct way to specify ranges in YAML, but some YAML can store serialized objects, for example in Ruby:

...
normal range: !ruby/range 10..20 
exclusive range: !ruby/range 11...20 
negative range: !ruby/range -1..-5 
...

Look here

缺⑴份安定 2024-09-18 10:30:16

范围是特定于应用的。以下内容对于某些应用程序可能有意义:

-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 ?)

不美如何 2024-09-18 10:30:16

安德烈是对的——不存在基本范围之类的东西。范围可以在全序数据类型之上定义。 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.

厌倦 2024-09-18 10:30:16

实际上,对于像这样的范围

下面这个呢?

第 10 至 15 页包含第 1 章

一种方法是

第 1 章:[10、11、12、13、14、15]

可以使用数组(元素 [0] 或偶数元素 - 起始页,元素 [1] 或奇数元素 - 结束页):

chapter1: [10, 15]

chapter2: [16, 20, 22, 40]

如果 Chapter2第 21 页有中断

Actually, for ranges like

What about the following?

Pages 10 to 15 contains chapter 1

One way is

chapter 1: [10, 11, 12, 13, 14, 15]

is possible to use arrays (element [0] or even elements - start page, element [1] or odd elements - end page):

chapter1: [10, 15]

chapter2: [16, 20, 22, 40]

if chapter2 has break on page 21

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文