是否有可能实现阴阳困惑在C#5.0使用异步? [英] Is it possible to implement the Yin-Yang puzzle in C# 5.0 using async?

查看:132
本文介绍了是否有可能实现阴阳困惑在C#5.0使用异步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的智力玩具,在方案实施,如下:

The puzzle, implemented in Scheme, is as follows:

(let* ((yin
     ((lambda (cc) (display #\@) cc) (call-with-current-continuation (lambda (c) c))))
   (yang
     ((lambda (cc) (display #\*) cc) (call-with-current-continuation (lambda (c) c)))))
(yin yang))

拼图的目标是制定和理解这个code的输出。

The goal of the puzzle is to work out and understand the output of this code.

我不知道是否有可能实现code,使用C#5.0的新异步CPS功能相同的语义。

I'm wondering if it's possible to implement code with the same semantics using C# 5.0's new async CPS features.

这是我无法把握的一部分,是拼图依靠让利的语义*不亚于呼叫/毫升。我不知道如何正确EX preSS这种相互影响在C#。

The part that I'm having trouble grasping, is that the puzzle relies on the semantics of let* as much as call/cc. I'm not sure how to correctly express this interplay in C#.

推荐答案

CPS可以摆脱电话/立方厘米的全部,所以你绝对可以通过手的CPS-荷兰国际集团就实现这在C#。知道任何关于C#的自动CPS-ING,我不能说这个功能是否会自动执行此操作。然而,在名称中的异步给了我暂停。你给现在的问题是明确相关的同步的这个前pression评价。

CPS can get rid of call/cc entirely, so you can definitely implement this in C# by hand-CPS-ing it. Knowing nothing about C#'s automatic CPS-ing, I can't say whether that feature will do this automatically. However, the "async" in the name gives me pause. The question you give is explicitly related to the synchronous evaluation of this expression.

我的意见:我觉得这个翻译到C#是不明白这个以最快的方式

My opinion: I think that translating this to C# is not the fastest way to understand this.

最后:让*是简写嵌套绑定。所以,你可以改写这个为:

Finally: let* is shorthand for nested bindings. So you can rewrite this as:

(let ([yin ...])
  (let ([yang ...])
     ...))

...摆脱让利*的。在你的情况,因为阳不依赖于阴,效果就是测序。也就是说,在'阴'的结合是一个右手边还未评估捕获该延续了阳的结合。

... to get rid of the let*. In your case, since 'yang' doesn't depend on 'yin', the effect is that of sequencing. That is, the continuation captured in the right-hand-side of the 'yin' binding is one that hasn't yet evaluated the 'yang' binding.

这篇关于是否有可能实现阴阳困惑在C#5.0使用异步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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