Simula 67中的C#迭代器和暂停/恢复 [英] C# iterators and suspend/resume in Simula 67

查看:69
本文介绍了Simula 67中的C#迭代器和暂停/恢复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

诸如Simula 67之类的语言包含协同程序的一般概念,

允许暂停执行某个方法而不回滚

堆栈然后再恢复它被暂停的地方相同。


C#迭代器似乎是这个常规暂停/恢复的特殊情况

概念。 收益率语句暂停执行当前方法

并调用MoveNext()恢复它。


我认为引入一般暂停/恢复概念会更清晰

到C#然后在这个基础之上实现C#迭代器。已经将C#迭代器添加到C#中的
方式似乎有点临时性;它是一个非常具体和独特的功能,并不会自然地与其他语言混合使用




Jiri

Languages such as Simula 67 contain a general concept of coroutines that
allow the execution of a method to be suspended without rolling back the
stack and then later resumed at the same place as it has been suspended.

The C# iterators seem to be a special case of this general suspend/resume
concept. The "yield" statement suspends the execution of the current method
and calling MoveNext() resumes it.

I think it would be cleaner to introduce the general suspend/resume concept
to C# and then implement C# iterators on top of this general foundation. The
way C# iterators have been added to C# seems to be somewhat ad hoc; it is a
very specific and distinct functionality that does not naturally blend with
the rest of the language.

Jiri

推荐答案

我不确定是否遵循这一点。 C#有一个收益率声明?

我想如果你想安排自己的方法,你可以查看

纤维。


-

William Stacey,MVP


" Jiri Kripac" <ジ********* @ autodesk.com>写在消息

news:ux ************** @ tk2msftngp13.phx.gbl ...
Not sure I follow that. C# has a yield statement?
I think if you want to schedule your own methods, you might look into
Fibers.

--
William Stacey, MVP

"Jiri Kripac" <ji*********@autodesk.com> wrote in message
news:ux**************@tk2msftngp13.phx.gbl...
语言如Simula 67包含协程的一般概念,即允许暂停执行方法而不回滚
堆栈,然后在暂停的同一地点恢复。
C#迭代器似乎是这种一般暂停/恢复概念的特例。 收益率语句暂停当前
方法的执行并调用MoveNext()恢复它。

我认为将一般暂停/恢复
概念引入C#会更清晰在这个基础之上实现C#迭代器。
C#迭代器添加到C#的方式似乎有些临时;这是
a非常具体和独特的功能,不会自然地将
与其他语言混合在一起。

Jiri
Languages such as Simula 67 contain a general concept of coroutines that
allow the execution of a method to be suspended without rolling back the
stack and then later resumed at the same place as it has been suspended.

The C# iterators seem to be a special case of this general suspend/resume
concept. The "yield" statement suspends the execution of the current method and calling MoveNext() resumes it.

I think it would be cleaner to introduce the general suspend/resume concept to C# and then implement C# iterators on top of this general foundation. The way C# iterators have been added to C# seems to be somewhat ad hoc; it is a very specific and distinct functionality that does not naturally blend with the rest of the language.

Jiri



" William Stacey [MVP]"
"William Stacey [MVP]"
不确定我是否遵循了这一点。 C#有一个yield语句?
Not sure I follow that. C# has a yield statement?




参见C#2.0规范。



See the C# 2.0 spec.




Jiri Kripac <ジ********* @ autodesk.com>写在消息

news:ux ************** @ tk2msftngp13.phx.gbl ...

"Jiri Kripac" <ji*********@autodesk.com> wrote in message
news:ux**************@tk2msftngp13.phx.gbl...
语言如Simula 67包含协程的一般概念,即允许暂停执行方法而不回滚
堆栈,然后在暂停的同一地点恢复。
C#迭代器似乎是这种一般暂停/恢复概念的特例。 收益率语句暂停执行当前的
方法
并调用MoveNext()恢复它。

我认为引入一般暂停/恢复概念会更清晰对于C#,然后在这个基础之上实现C#迭代器。
C#迭代器添加到C#的方式似乎有点临时性;它是一个非常具体和独特的功能,不会自然地与其他语言混合。


自从我第一次阅读迭代器以来,我有同样的看法,但是我的主要问题是在迭代之外找到一个真正的用途,其中coroutines

将是有价值的,仍然是一个干净的解决方案。

之外是否有一个原因(并且这是因为增加了复杂性的原因)

迭代了一系列无法​​解决的值更干净的方式

使用类状态而不是方法状态?


Jiri
Languages such as Simula 67 contain a general concept of coroutines that
allow the execution of a method to be suspended without rolling back the
stack and then later resumed at the same place as it has been suspended.

The C# iterators seem to be a special case of this general suspend/resume
concept. The "yield" statement suspends the execution of the current
method
and calling MoveNext() resumes it.

I think it would be cleaner to introduce the general suspend/resume
concept
to C# and then implement C# iterators on top of this general foundation.
The
way C# iterators have been added to C# seems to be somewhat ad hoc; it is
a
very specific and distinct functionality that does not naturally blend
with
the rest of the language.
I''ve had the same opinion since I first read about iterators, however my
main problem is finding a real use outside of iteration where coroutines
would be of value and still be a clean solution. Is there a reason for
it(and derived from that a reason for the added complexity) outside of
iterating across a series of values that can''t be solved in a cleaner manner
using class state instead of method state?


Jiri



这篇关于Simula 67中的C#迭代器和暂停/恢复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆