基于函数式方法的CGI程序设计

Abstract

由于HTTP 天生的无状态性质,Web 程序设计中产生了这样一个问题:在两个连续的用户交互之间会遗忘状态信息。一个交互性的 Web 应用程序由一组脚本构成,每个交互都包含两个脚本,一个脚本向浏览器递交页面(然后结束),用户及时完成并提交表单,然后另一个(可能是不同的)脚本处理提交的表单。所以,应用程序逻辑分布在多个脚本之间。 由于浏览器还允许用户在交互中回溯,或者克隆一个正在处理中的交互过程,之后并行执行这两个交互过程,所以问题变得更加复杂。Web 开发框架(例如 Spring 和 Struts)允许处理多个交互,但是它们进一步提高了整体上已经很复杂的代码库的复杂性。 在本文中,我们将几种函数式方法应用到Web程序设计中,从而简化复杂 Web 应用程序的开发。我将从介绍 continuation 的应用开始,逐步引入CPS,Trampoline,Lambda Lifting等函数式方法,通过用Scheme语言编写的一个CGI实例详细展示函数式方法的效果,并进一步将这些方法在C语言中实现。Due to the inherent stateless nature of HTTP, Web technologies suffer from the problem of state information being forgotten between two successive user interactions. An interactive Web application consists of a collection of scripts wherein a single interaction comprises one script delivering a page to the browser (then ending), the user completing and submitting the form at some later point in time, and another (possibly different) script handling the submitted form. Thus, application logic is spread across a multitude of scripts. Matters are further complicated by the fact that browsers allow users to backtrack in their interactions or clone an in-progress interaction and run both in parallel. Web development frameworks, such as Spring and Struts, allow programmers to handle multiple navigational paths, but they cost of increasing the complexity of code base. In this thesis, we introduce several functional methods into Web programming, in order to simplify the complexity of Web development. We’ll start from the application of continuation, and then utilize CPS, trampoline and lambda lifting step by step. A instance of CGI script programmed in Scheme will be shown later, to display how these methods work, and will be further implemented in the language C

    Similar works