{"title":"Formalizing dynamic-wind in the lambda calculus","authors":"Ryotaro Kasuga, S. Nishizaki","doi":"10.1145/3524304.3524318","DOIUrl":null,"url":null,"abstract":"The Scheme programming language has the control constructs: call-with-current-continuation (call/cc) and dynamic-wind. The construct call/cc is a procedure to handle first-class continuations. The construct dynamic-wind is a procedure to hook a continuation captured by call/cc. It can add pre- and post-processing to a continuation, and allows flexible handling of global escape and control effect by continuation calls. The first example where the continuation is applied is rewriting variables with dynamic scope, and the second is saving and restoring registers during context switching of threads implemented in user space. On the other hand, dynamic-wind is very difficult to understand in Scheme. In fact, the semantics of dynamic-wind represent one of the most complicated mechanisms in Scheme. The semantics presented in the revised Scheme language definition remain complicated, and it is difficult to understand the behavior and write programs correctly. In this article, we focus on three main uses of dynamic-wind: resource allocation at continuous invocation time, and resource release at global escape time. The use of dynamic-wind is focused on resource management, and formalize resource state and resource operations in this paper. For the dynamic-wind modeled in such a way, we propose a type system and an effect system to track the resource state. In most of the discussions in this paper, we have simplified the model of dynamic-wind to clarify the theory. However, we will show that the method can be applied to more complex situations in practice.","PeriodicalId":420523,"journal":{"name":"Proceedings of the 2022 11th International Conference on Software and Computer Applications","volume":"11 1","pages":"0"},"PeriodicalIF":0.0000,"publicationDate":"2022-02-24","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"1","resultStr":null,"platform":"Semanticscholar","paperid":null,"PeriodicalName":"Proceedings of the 2022 11th International Conference on Software and Computer Applications","FirstCategoryId":"1085","ListUrlMain":"https://doi.org/10.1145/3524304.3524318","RegionNum":0,"RegionCategory":null,"ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"","JCRName":"","Score":null,"Total":0}
引用次数: 1
Abstract
The Scheme programming language has the control constructs: call-with-current-continuation (call/cc) and dynamic-wind. The construct call/cc is a procedure to handle first-class continuations. The construct dynamic-wind is a procedure to hook a continuation captured by call/cc. It can add pre- and post-processing to a continuation, and allows flexible handling of global escape and control effect by continuation calls. The first example where the continuation is applied is rewriting variables with dynamic scope, and the second is saving and restoring registers during context switching of threads implemented in user space. On the other hand, dynamic-wind is very difficult to understand in Scheme. In fact, the semantics of dynamic-wind represent one of the most complicated mechanisms in Scheme. The semantics presented in the revised Scheme language definition remain complicated, and it is difficult to understand the behavior and write programs correctly. In this article, we focus on three main uses of dynamic-wind: resource allocation at continuous invocation time, and resource release at global escape time. The use of dynamic-wind is focused on resource management, and formalize resource state and resource operations in this paper. For the dynamic-wind modeled in such a way, we propose a type system and an effect system to track the resource state. In most of the discussions in this paper, we have simplified the model of dynamic-wind to clarify the theory. However, we will show that the method can be applied to more complex situations in practice.