Introduction to Scheme
The most important, but at the same time the most imperceptible property of any tool is its influence on the formation of the habits of people who tend to use it.
Edsger Vyb Dijkstra
Part 1 Introduction to Scheme
Part 2 Deepening in Scheme
Part 3 IronScheme Practice
When should I use Lisp and when not? This article is devoted to various articles on the Internet. I do not presume to discuss this topic, but only notice where Lisp came in handy. For the most part, I used Lisp as an embedded language. To manage applications through the console, to create flexible configuration files, to store structured data, to transfer data over a network, to implement home
I do not consider myself a specialist in the Lisp world and I do not guarantee 100% accuracy of the material presented. One of the goals of this series of articles is to collect disparate information on various Scheme implementations in one place and in their native language. In general, this material is not for those who want to know why, but for those who want to know how. If someone will find the topic interesting and useful, write, we will clarify what is and think about the continuation.
Almost every article about Lisp starts with Lisp being one of the oldest high-level and general-purpose programming languages that was invented by John McCarthy around 1958. Despite the antiquity of Lisp, it is a multi-paradigm language that allows you to write in functional, procedural, object-oriented styles. At the same time, all this multiparadigmality is available through a primitive and uniform syntax, the so-called S-expressions. To describe Lisp syntax in the form of Backus-Naura, only 7 lines are enough, with reservations of course. It so happened that over the long history of development over Lisp the best minds of computer sciences have puzzled, polishing it like a gem. However, you can’t say that Lisp is very popular, perhaps due to a frightening pile of brackets, because of which, at first glance, the program looks complicated to perceive. But after a little practice, discomfort passes into delight from the possibilities that this method of programming provides. At least it was with me).
To be more precise, Lisp is not so much a programming language as an idea, on the basis of which the languages of the Lisp family are developed. Today, there are a great many Lisp dialects, and there are even more implementations of them. Which is not surprising, because writing a Lisp interpreter is relatively easy. So the wheel of history turned that Common lisp, Scheme and Clojure became the most popular dialects. Each dialect pursues its own, slightly different goals. Common Lisp is a rather old industry standard; it has in its arsenal not a small number of libraries and developments. Scheme - seeks to minimize the basic constructions through which all other functionality, a variety of styles and programming approaches can be expressed. That is, a minimalist interpreter and a developed standard library. Clojure - a fresh look at Lisp in general, many language constructs have been rethought for convenient development on top of the JAVA platform in the first place. As they write on the forums, developing under Clujure is much more productive and interesting than on JAVA. For the sole purpose of self-study, I tasted different dialects and their implementation. You can argue Scheme vs Common Lisp indefinitely, but for myself I made a choice in favor of Scheme for its conciseness, modernity and accessibility of implementations on various platforms.
You can find reviews about Scheme on forums, as if it is an exclusively academic language, which, if it can be used in practice, is extremely inconvenient due to excessive minimalism. Something told me, it is not so. And now, my dear reader, I’ll tell you that scheme, a rather flexible programming language, is not overloaded with cunning designs and can successfully compete with many popular tools. And using it as an embedded language is a pleasure. The relative simplicity of the Scheme standard plays into the hands of many other implementations. In fact, you can choose an implementation for any needs and develop full-fledged GUI, DB, WEB applications using Scheme as the main language.
There are plenty to choose from
It is curious, but often the most popular products practically do not provide a choice, here is the only and unique version for you, and everything else is either outdated or someone else’s homemade product.
Scheme, perhaps due to the simplicity of the standard, has quite a few implementations, either interpreters, or compilers, or both at once. Moreover, there are compilers in other languages, which in some cases can be extremely useful.
A list of known implementations can be found on the net, for example, a table is published on community.schemewiki.org .
Known Scheme implementations
And if you search thoroughly on GitHub , it becomes clear that there are even more options.
Following the standard in various implementations allows you to reuse code on different platforms, including for Web programming. But do not forget that functionality that is not part of the standard is likely to differ, which will lead to portability of the code.
More often in my practice I come across programming for .NET. Therefore, the solution that allows me to use .NET libraries and embed the Scheme interpreter in my applications is most useful to me. After playing with different options, I settled on IronScheme . So, how it, at first glance, seemed the most advanced implementation of the R6Rs standard for .NET. But there are others that will be written about in future articles.
IronScheme implements the sixth version of the R6Rs standard. Naturally, it has built-in functionality for interacting with the clr runtime. Thus, directly from the Scheme script we can create and manipulate .NET classes. And this is already enough to create a full-fledged application with GUI, DB and other goodies that are available from .NET. But we are not required to write full programs on IronScheme. Moreover, the supplied libraries have wrappers for a small number of standard .NET classes. Although no one is stopping us from helping the community.
- To start using IronScheme download the archive from ironscheme.codeplex.com/;
- unpack for example in “Program Files (x86)”;
- add to the PATH environment variable "C: \ Program Files (x86) \ IronScheme \";
- for convenience, in the directory with IronScheme I create a file “is.bat” with the contents of “IronScheme.Console-v4.exe% 1”;
- By executing the IronScheme.Console-v4.exe command, run the interpreter in REPL mode.
Now you can enter commands, for example, "(+ 2 2)". The interpreter in REPL mode supports autocompletion by pressing TAB, which is convenient to use as a reference command or to check code fragments. To exit the interpreter, type “(exit)”.
By tradition, we’ll write and launch the Hello world application. In any familiar text editor, preferably supporting Scheme, such as Sublime , create a file and save it hello-world.ss.
The contents of the hello-world.ss file:
(import (rnrs) (ironscheme) ) (displayln "Hello, world!")
We start the command "IronScheme.Console-v4.exe hello-world.ss" as a result we get the long-awaited inscription.