RepeatingElement[spec]
表示解释器、API 或形式规范中任意重复类型的元素.
RepeatingElement[spec,max]
表示一个可以出现最多 max 次的元素.
RepeatingElement[spec,{min,max}]
表示一个可以出现 min 和 max 次的元素.
RepeatingElement[spec,{n,{min,max}}]
表示一个最初以格式出现 n 次的元素.
RepeatingElement[spec,{{i,n},{min,max}}]
表示一个元素,其中 i 取连续值.
RepeatingElement
RepeatingElement[spec]
表示解释器、API 或形式规范中任意重复类型的元素.
RepeatingElement[spec,max]
表示一个可以出现最多 max 次的元素.
RepeatingElement[spec,{min,max}]
表示一个可以出现 min 和 max 次的元素.
RepeatingElement[spec,{n,{min,max}}]
表示一个最初以格式出现 n 次的元素.
RepeatingElement[spec,{{i,n},{min,max}}]
表示一个元素,其中 i 取连续值.
更多信息
- 在 Interpreter 的上下文中, spec 可以是任何用于 Interpreter 的规范,包括 CompoundElement 或 RepeatingElement.
- 在 FormObject 和 FormFunction 上下文中, spec 可以是任何用于格式的规范,包括完整关联和 CompoundElement.
- 如果没有指定最小重复,RepeatingElement 起初以一个格式表示一个单个元素.
- Interpreter[RepeatingElement[spec]][input] 有效等价于 Interpreter[spec][input],因为 Interpreter 自动在 input 中列出.
- RepeatingElement 可以嵌套出现在 Interpreter 上下文中的 CompoundElement 规范.
范例
打开所有单元 关闭所有单元基本范例 (5)
RepeatingElement 可用于 FormFunction 以重复一个字段:
FormFunction["field" -> RepeatingElement["String"]][]也可以通过编程方式填充 RepeatingElement 字段:
api = APIFunction["field" -> RepeatingElement["City"], f];
api["field" -> {"helsinki", "goteborg"}]api["field[1]" -> "oslo"]在 APIFunction 中,RepeatingElement 指定应该使用特定参数的所有实例:
APIFunction[{"x" -> RepeatingElement["Integer"]}, #x ^ 2&][{"x" -> 2, "x" -> 3}]如果没有 RepeatingElement,则仅使用最后一个实例:
APIFunction[{"x" -> "Integer"}, #x ^ 2&][{"x" -> 2, "x" -> 3}]Interpreter 线性作用于列表,因此这里不需要 RepeatingElement:
Interpreter[RepeatingElement["Integer"]][{"1", "2", "5"}]Interpreter["Integer"][{"1", "2", "5"}]Interpreter[CompoundElement[{"Integer", RepeatingElement["Integer"]}]][{"6", {"1", "2", "3"}}]RepeatingElement 可用于限制元素个数:
Interpreter[RepeatingElement["Integer", 2]][{"1", "7"}]Interpreter[RepeatingElement["Integer", 2]][{"1", "7", "5"}]范围 (3)
Interpreter[RepeatingElement["String", 2]][{"foo", "bar", "baz"}]Interpreter[RepeatingElement["String", {3, 5}]][{"foo", "bar"}]CloudDeploy[FormFunction["field" -> RepeatingElement["String", {2, {1, 5}}]]]CloudDeploy[FormFunction["number of occupants" -> RepeatingElement[<|"Interpreter" -> "Integer", "Label" :> "room " <> ToString[i]|>, {{i, 2}, {1, 5}}]]]属性和关系 (4)
将 RepeatingElement 与 CompoundElement 联合使用以解释复杂的结构:
Interpreter[CompoundElement[<|"numbers" -> RepeatingElement["Integer"], "fruit" -> RepeatingElement[{"apple" -> "pomme", "orange" -> "orange", "grapefruit" -> "pamplemousse"}]|>]][<|"numbers" -> {"1", "14", "-4"}, "fruit" -> {"apple", "pomme", "grapefruit"}|>]将其与 Alternatives 联合使用以解释可以具有不同形状的数据:
Interpreter[CompoundElement[<|"x" -> RepeatingElement["City" | "Country"]|>]][<|"x" -> {"berlin", "portugal", "tegucigalpa"}|>]Interpreter[CompoundElement[<|"x" -> RepeatingElement["AmusementPark"]|>]][<|"x" -> {"coliseum" | "disneyland", "six flags" | "central park" }|>]RepeatingElement 不应与 DelimitedSequence 混淆. RepeatingElement 不允许单一字符串用分隔符分开:
Interpreter[RepeatingElement["Integer"]]["1,2,3"]对于用分隔符分开的元素,使用 DelimitedSequence:
Interpreter[DelimitedSequence["Integer"]]["1,2,3"]在 FormFunction 的上下文中,与 CompoundElement 一起使用,以生成字段表格:
CloudDeploy[FormFunction["names" -> RepeatingElement[CompoundElement[<|"first" -> "String", "last" -> "String"|>]]]]可能存在的问题 (1)
当把 RepeatingElement 的第二个参数与网络表单或 API 中的索引一起使用时,"Interpreter" 字段不能依赖索引:
FormObject["x" -> RepeatingElement[<|"Interpreter" :> Range[i], "Label" :> ToString[i]|>, {{i, 1}, {1, 4}}]]FormObject["x" -> <|"Interpreter" :> (Print["evaluated"];"String")|>]//InputForm相关指南
-
▪
- 表单结构与布局 ▪
- 设置输入解释器 ▪
- 自由格式和外部输入 ▪
- 创建表单界面和应用程序
文本
Wolfram Research (2015),RepeatingElement,Wolfram 语言函数,https://reference.wolfram.com/language/ref/RepeatingElement.html.
CMS
Wolfram 语言. 2015. "RepeatingElement." Wolfram 语言与系统参考资料中心. Wolfram Research. https://reference.wolfram.com/language/ref/RepeatingElement.html.
APA
Wolfram 语言. (2015). RepeatingElement. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/RepeatingElement.html 年
BibTeX
@misc{reference.wolfram_2026_repeatingelement, author="Wolfram Research", title="{RepeatingElement}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/RepeatingElement.html}", note=[Accessed: 15-November-2026]}
BibLaTeX
@online{reference.wolfram_2026_repeatingelement, organization={Wolfram Research}, title={RepeatingElement}, year={2015}, url={https://reference.wolfram.com/language/ref/RepeatingElement.html}, note=[Accessed: 15-November-2026]}