Bringing Scheme programming to the iPhone-Experience

Engineer Bainomugisha, Jorge Vallejos, Elisa Gonzalez Boix, Pascal Costanza, Theo D'Hondt, Wolfgang De Meuter
2012 Software, Practice & Experience  
The iPhone SDK provides a powerful platform for the development of applications that make use of iPhone capabilities such as sensors, GPS, Wi-Fi or Bluetooth connectivity. Thus far we observe that the development of iPhone applications is mostly restricted to using Objective-C. However, developing applications in plain Objective-C on the iPhone OS suffers from limitations such as the need for explicit memory management and lack of syntactic extension mechanism. Moreover, when developing
more » ... ted applications in Objective-C, programmers have to manually deal with distribution concerns such as service discovery, remote communication, and failure handling. In this paper, we discuss our experience on porting the Scheme programming language to the iPhone OS and how it can be used together with Objective-C to develop iPhone applications. To support the interaction between Scheme programs and the underlying iPhone APIs, we have implemented a language symbiosis layer that enables programmers to access the iPhone SDK libraries from Scheme. In addition, we have designed high-level distribution constructs to ease the development of distributed iPhone applications in an event-driven style. We validate and discuss these constructs with a series of examples including an iPod controller, a maps application and a distributed multiplayer Scrabble-like game. We discuss the lessons learned from this experience for other programming language ports to mobile platforms. key words: iPhone development; Scheme; Objective-C; language symbiosis; interactive scripting environment; event-driven programming While newer versions of Objective-C for the desktop platforms (Mac OS X v10.5 and later) support automatic memory management, there is no automatic garbage collection in the iPhone runtime system. ‡ iScheme is based on a Scheme interpreter [9] that is developed at our laboratory. We chose to use a locally developed Scheme implementation primarily because of the availability of the source code as well as its author. :1-7 Prepared using speauth.cls BRINGING SCHEME PROGRAMMING TO THE IPHONE 3 the environment (e.g., changes in the orientation or physical position of the phone, network events, user input, etc.). In this respect, Moby Scheme provides some support for event-driven programming which allows programs to react to a set of predefined events such as changes in the orientation of the phone. While there is some integration of event-driven programming on these existing ports, none of them provides constructs for distribution operating on top of the runtime platforms for distribution for Java or Objective-C. For instance, network disconnections need to be manually dealt with using a classic exception handling mechanism. This results in application code where exception handling is scattered all over the program. We note that disconnections cannot be ignored as in the case of desktop applications, since they are omnipresent in a mobile setting [23, 8] . In this work, we take a different approach to support Scheme and Objective-C interaction. Rather than using the FFI approach, iScheme employs Objective-C reflective API. This enables direct interaction between Scheme and Objective-C without need for writing wrapper functions in C. More concretely, we built a language symbiosis layer between Scheme and Objective-C that enables access to the Objective-C APIs from Scheme programs. Language symbiosis has been proposed in existing works as a means to enable two programs written in different languages to invoke each other's behaviour and exchange data [18] . With this symbiosis in place, iScheme provides developers with an event-driven programming model for accessing iPhone capabilities, with higher-order functions used as event handlers. In Objective-C, event-driven programs are typically organised around the notion of delegates, which serve as callbacks whose methods are invoked when a particular event occurs. Using higher-order functions as event handlers maps well onto such an event-driven architecture while keeping the simplicity of the Scheme programming model. From prior work at our lab, we have found that such an event-driven programming model is also suited for the development of distributed applications running on mobile devices [6] . As such, iScheme provides built-in constructs for service discovery (built on top of the Bonjour framework), asynchronous remote messaging (built on top of TCP/IP), and failure handling. This allows distribution concerns to be encapsulated in high-level constructs while relieving programmers of the difficulties engendered by distribution. The contributions of this paper are: we port Scheme, which is a small but rich interpreted language, to the iPhone platform. We engineer a language symbiosis between Scheme and Objective-C by way of a reflective approach, which facilitates access to the iPhone APIs in an event-driven style. We design and implement event-driven distribution constructs specially tailored for mobile computing environments. In particular, our distribution constructs have built-in support for peer-to-peer service discovery, asynchronous remote messaging, and failure handling. We discuss our experience and summarise techniques of implementing language symbiosis with Objective-C. Our experience should serve as a stepping stone for Scheme programmers interested in developing applications for the iPhone, researchers that design languages for mobile devices as well docents teaching introductory programming courses. In addition, our experience may serve as a basis for other language ports to mobile devices employing runtime platforms with reflective capabilities, such as those found in the iPhone and the Android devices. Availability: iScheme packaged as a scripting environment, is available for download at
doi:10.1002/spe.1073 fatcat:vbqj2vdsqnafha35t2avukpnci