序列是否称为Kotlin中的内部DSL?
它在“ Kotlin In Action”一书中说,Kotlin DSL结构最常通过链式方法调用创建。此外,一个典型的库由许多方法组成,并且不保留上下文。
我对哪个侧序接近我感到困惑。在阅读本文之前,我认为序列只是库的API,但它确实符合DSL的功能。
In book 'Kotlin in Action', it says Kotlin DSL structure is most commonly created through chained method calls. Also, a typical library consists of many methods and no context is maintained btw one call and the next.
I'm confused of which side sequence is close to. Before I read this, I've thought sequence is just API of library, but it really fits with feature of DSL.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不是100%确定这回答了您的问题,但是我不会将
sequence
管道视为“ DSL”本身,特别是因为它是一般的,这与“域”相反 - 特定的” - DSL定义的核心。如果您基于链接的方法来构建自己的构建器API,请注意特定域,您 可以将其视为DSL,但我想说Kotlin DSL主要由具有声明性的财产分配的嵌套lambdas制成,而是比链方法调用。
这是因为Kotlin中的Lambdas给出了块和结构的错觉,而不是实际的功能和功能调用,这就是为什么这样的嵌套结构看起来像他们自己的“语言”(DSL的L)。链式方法调用看起来不像另一个“语言” - 它们看起来像功能调用,但这当然是我的主观措施。
例如,这是使用Gradle Kotlin DSL的Gradle Build脚本:
dos 看起来像其自己的语言,在阅读此类代码时,您不会立即想到Kotlin。
I'm not 100% sure this answers your question, but I would not think of
Sequence
pipelines as a "DSL" per se, in particular because it is quite general, which is the opposite of "domain-specific" - the heart of the definition of a DSL.If you build your own builder API based on chained method calls for a specific domain, you could consider that as a DSL, but I would say Kotlin DSLs are mostly made of nested lambdas with declarative property assignments, rather than chained method calls.
This is because lambdas in Kotlin give the illusion of blocks and structure more than actual functions and function calls, which is why nested structures like this look like their own "language" (the L of DSL). Chained method calls don't look like another "language" - they just look like function calls, but of course that's my subjective take.
For example, here is a Gradle build script using the Gradle Kotlin DSL:
It does look like its own language, you don't immediately think of Kotlin when reading such code.