Rebol:为什么 get-access-modifier 被调用两次而它应该只被调用一次
在 rebol 控制台中输入时,
do read http://askcodegeneration.com/csharp/simple-class/
我得到 get-access-modifier 调用两次:
Access modifier:
1. private: member can be accessed only by code in the same class
2. protected: member can be accessed only by code in the same class or in a derived class
3. internal: member can be accessed only by code in the same assembly
4. public: member can be accessed by code in the same assembly or another assembly that references it choice (by default 1):
Access modifier:
1. private: member can be accessed only by code in the same class
2. protected: member can be accessed only by code in the same class or in a derived class
3. internal: member can be accessed only by code in the same assembly
4. public: member can be accessed by code in the same assembly or another assembly that references it choice (by default 1):
而它在源代码中只提到一次:
append fields-template-output form reduce [
(to-word get-access-modifier) field-layout
]
我真的不明白为什么,你能吗?
When typing in rebol console
do read http://askcodegeneration.com/csharp/simple-class/
I get get-access-modifier called twice:
Access modifier:
1. private: member can be accessed only by code in the same class
2. protected: member can be accessed only by code in the same class or in a derived class
3. internal: member can be accessed only by code in the same assembly
4. public: member can be accessed by code in the same assembly or another assembly that references it choice (by default 1):
Access modifier:
1. private: member can be accessed only by code in the same class
2. protected: member can be accessed only by code in the same class or in a derived class
3. internal: member can be accessed only by code in the same assembly
4. public: member can be accessed by code in the same assembly or another assembly that references it choice (by default 1):
Whereas it is only mentioned once in the source code:
append fields-template-output form reduce [
(to-word get-access-modifier) field-layout
]
I really can't see why, can you ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的。只有一次对它的调用,但它位于
foreach
内部。您的默认值是两个字段,因此您会被询问两次。输入更多,您会被问到更多。虽然您可以(并且可能应该)将其保存在变量中,但 Rebol 还有其他方法。例如,您可以
组合
代码块:组合运行一次,深入查找代码块中的括号,并计算代码。 (类似于解析看到括号时的方式)。剩下的就不用管了。因此,完成替换的块将被传递到 FOREACH 中以运行循环。
只是您如何可能有一个看似在循环内但仅执行一次的调用的细微差别。我不建议将它用于类似的事情。
我建议的是通过学习更多的 Rebol 原语(例如 REJOIN...它从一个块中构建一系列)来研究如何减少代码中的冗余。系列类型将匹配它看到的第一个类型(如果第一个元素不是系列,则为字符串):
Yes. There is only one call to it, but it's inside of a
foreach
. Your default is two fields, so you get asked twice. Enter more, you'll get asked more.While you could (and probably should) do the obvious thing of saving it in a variable, Rebol has other ways. For instance you could
compose
the block of code:The composition runs once, looks deep for the parentheses in the block, and evaluates the code. (Kind of how parse does when it sees parentheses). The rest is left alone. So the block with the substitutions done is what's passed into FOREACH to run the loop.
Just a nuance of how you could have a call that appears to be inside a loop and yet is executed only once. I wouldn't suggest using it for something like this.
What I would suggest is studying making things less redundant in your code, by learning some more Rebol primitives like REJOIN...which builds a series out of a block. The series type will match whatever the first type it sees is (or a string if the first element is not a series):
为了解决这个问题,我使用 static var 来检测它只执行一次(感谢 Sunanda 提示 rebol 函数内是否可以有静态变量?)。
To solve the problem I have used static var to detect that it is executed only once (thanks to Sunanda tips is it possible to have static variable inside a rebol function? ).