⬆️ ⬇️

Scheme Introduction



The most important, but at the same time, the most imperceptible property of any instrument is its influence on the formation of the habits of people who tend to use it.

Edsger Waib Dijkstra




Part 1 Introduction to Scheme

Part 2 Groove in the Scheme

Part 3 Practicing IronScheme



Introduction



In programming practice, there is often a need to write small scripts for automating various administrative processes, testing and monitoring. It is also not rare that there is a need to embed any interpreter in an application or simply create a prototype to test an idea. For these purposes, you can use various popular tools JavaScript, Python, Lua, Bash, BAT, PHP and much more. And there is also the need to store structured data in files or to transfer over the network, when it comes to text formats, XML, JSON, CSV, even KV are usually used. However, despite the advantages and prevalence of such well-known tools, I did not leave the obsession with finding a more flexible and elegant tool. Thus, I once paid attention to the Lisp language family. And Lisp allowed to shoot all the birds with one stone at once, and beautiful and elegant. Since it has many implementations and standards for any needs and tastes. It can act as an independent language, and embedded. It has a uniform presentation of data and program code. And most importantly, if necessary, writing your own interpreter is not an impossible task.

')

When should Lisp be used and when not? This issue is devoted to various articles on the Internet. I do not presume to discuss this topic, but only note where Lisp came in handy to me. 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 the network, to implement self - made self - made RPC. In my opinion, it is convenient when all the listed options have the same syntax, and they can also be expanded (in terms of syntax and functionality), and on the fly.



I do not consider myself a specialist in the world of Lisp and do not guarantee 100% accuracy of the material presented. One of the goals of this series of articles is to collect scattered information regarding different implementations of Scheme in one place and in the native language. In general, this material is not for those who want to know why, but for those who want to know how. If the topic is interesting and useful to someone, write, we will clarify what is and think about the continuation.



Start



Almost every Lisp article begins with the fact that Lisp is one of the oldest high-level and general-purpose programming languages ​​that was invented around 1958 by John McCarthy. Despite antiquity, Lisp is a multi-paradigm language that allows writing in functional, procedural, object-oriented styles. At the same time, all this multi-paradigm is accessible through a primitive and uniform syntax, the so-called S-expressions. To describe Lisp syntax in the form of Backus — Naur, only 7 lines are enough, with reservations of course. It so happened that in the long history of development over Lisp, the best minds of computer science puzzled, polishing it like a precious stone. However, it cannot be said that Lisp is very popular, perhaps because of the frightening jumble of brackets, because of which, at first glance, the program looks difficult to read. But after a little practice, the discomfort turns into a delight from the possibilities offered by this method of programming. At least that's how it was with me).



To be a little more precise, Lisp is not so much a programming language, as much as an idea, on the basis of which Lisp-family languages ​​are developed. These days there are a great many Lisp dialects, and their implementations are even greater. What is not surprising, because writing a Lisp interpreter is relatively easy. So turned the wheel of history, that Common lisp, Scheme and Clojure became the most popular dialects. Each dialect has its own slightly different goals. Common Lisp is a fairly old industry standard, has in its arsenal not a small number of libraries and developments. Scheme - strives for the minimality of basic constructions through which all other functionality, variety of styles and programming approaches can be expressed. That is, a minimalist interpreter and an advanced standard library. Clojure - A fresh look at Lisp as a whole, many of the language constructs were rethought for convenient development on top of the JAVA platform in the first place. How to write on the forums to develop under Clujure much more productive and more interesting than on JAVA. Solely for self-study, I tasted different dialects and their implementation. You can argue Scheme vs Common Lisp indefinitely, but for myself I made the choice in favor of Scheme for the brevity, modernity and availability of implementations on various platforms.



You can find reviews on Scheme in the forums, as if this 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. And now, my dear reader, I will tell you that the scheme is a rather flexible programming language, and it is not overloaded with cunning designs and can successfully compete with many popular tools. And to use it as an embedded language is a pleasure. The relative simplicity of the standard Scheme plays into its hands, contributing to the emergence of many 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's the one and only unique version for you, and everything else is either outdated or someone's home-made product.



Scheme, possibly due to the simplicity of the standard, has quite a few implementations, either interpreters, or compilers, or both. Moreover, there are compilers in other languages, which in some cases can be extremely useful.



A list of known implementations can be found online; for example, a table has been published on community.schemewiki.org .

Known Scheme Implementations


NameLinkTypePlatformActiveR7rs
BDC Schemecarlstrom.com/bdc-schemeinterpreterJavano
Bigloowww-sop.inria.fr/mimosa/fp/Bigloocompilermanyyes
Bitgithub.com/melvinzhang/bit-schemeinterpreterHardware (microcontrollers)no
BiwaSchemewww.biwascheme.orginterpreterJavascriptyes
Bus schemerubygems.org/gems/bus-schemeinterpreterRubyno
Chez schemewww.scheme.cominterpreter (free) + compiler (paid)manyno
chibi-schemecode.google.com/p/chibi-schemeinterpreterC (library)yesyes
Chickenwww.call-cc.orginterpreter + compilermanyyesyes
CPSCMwww.omnigia.com/scheme/cpscm/homecompilerJavascript, Common Lispno
Elksam.zoy.org/projects/elkinterpreterC ++ (library)no
Fomentcode.google.com/p/fomentinterpretermanyyesyes
Gambitwww.iro.umontreal.ca/~gambitinterpreter + compilermanyyes
Gauchepractical-scheme.net/gauche/index.htmlinterpretermanyyesyes
Guilewww.gnu.org/software/guileinterpretermanyyesyes
Heistgithub.com/jcoglan/heist/tree/masterinterpreterRubyno
Hschemehscheme.sourceforge.netinterpreterHaskellno
Husk Schemegithub.com/justinethier/husk-schemeinterpreterHaskellyesyes
Ikarus schemelaunchpad.net/ikaruscompilermanyno
Inlab-schemewww.inlab.de/scheme/index.htmlinterpreterLinuxno
Ironschemewww.codeplex.com/IronSchemeinterpreter.Netyes
Jajapagesperso-systeme.lip6.fr/Christian.Queinnec/Java/Jaja.htmlinterpreterJavano
Jschemejscheme.sourceforge.netinterpreterJavano
Kawawww.gnu.org/software/kawainterpreterJavayesyes
Ksiksi.sourceforge.netinterpreterC (library)no
KSMsquare.umin.ac.jp/~hchang/ksminterpreterC (library, Linux-only)no
Larcenywww.larcenists.orgcompilermanynoyes
libreplibrep.sourceforge.netinterpreterC (library)no
Lispmewww.lispme.de/lispme/index.htmlinterpreterPalmno
Llavallava.orginterpreterJavano
Lunasourceforge.net/projects/luna-schemecompiler.Netno
Microschemegithub.com/ryansuchocki/microschemecompilerHardware (Atmel)yes
MIT / GNU Schemewww.gnu.org/software/mit-schemeinterpretermanyyes
Minor schemewww.red-bean.com/trac/minorcompilerCno
Mschememscheme.sourceforge.netinterpreterJavano
mosh-schemecode.google.com/p/mosh-schemeinterpretermanyno
NexJ Schemenexj-scheme.orginterpreterJavano
Oaklispoaklisp.alioth.debian.orginterpreterPosixno
Ocsgithub.com/felix-lang/ocsinterpreterOcamlno
Owl lispcode.google.com/p/owl-lispinterpreterPosixnoyes
Picringithub.com/picrin-scheme/picrininterpreterC99yesyes
Pixie Scheme IIIJayReynoldsFreeman.com/My/Pixie_Scheme_III.htmlinterpreter + compileriPadyesno
Pocket schemewww.mazama.net/scheme/pscheme.htminterpreterWindows CEno
PS3Ipagesperso-systeme.lip6.fr/Christian.Queinnec/VideoC/ps3i.htmlinterpreterJavano
Psychewww.xs4all.nl/~yduppen/site/psyche.htmlinterpreterPythonno
QSchemewww.sof.ch/dan/qscheme/index-e.htmlinterpreterPosixno
Racketwww.racket-lang.orginterpreter + compilermanyyes
Rhizome / piwww.kt.rim.or.jp/~qfwfq/rhiz-pi/index-e.html??
Rschemegithub.com/bitwize/rscheme??
Sagittariuscode.google.com/p/sagittarius-schemeinterpretermanyyesyes
Scheme 9 from Empty Spacet3x.org/s9fesinterpreterC89 / POSIX, Plan 9yes
Scheme48s48.org??
Scheme-to-Cscheme2c.alioth.debian.org??
Chemhemschemik.sourceforge.net??
Chemhemwww.abstractnonsense.com/schemix??
SCMswissnet.ai.mit.edu/~jaffer/SCM.html??
Shoenocrew.org/software-shoe.html??
Siscsisc.sourceforge.net??
SIODpeople.delphiforums.com/gjc/siod.html??
Sigschemecode.google.com/p/sigscheme??
Sizzlewww.grabmueller.de/martin/www/sizzle/sizzle.en.html??
Stalinwww.ece.purdue.edu/~qobi/software.html??
STKlosstklos.sourceforge.net??
SXMwww.malgil.com/sxm??
s7ccrma.stanford.edu/software/snd/snd/s7.htmlinterpreterCyes
TinySchemetinyscheme.sourceforge.net??
UCB Schemewww-inst.eecs.berkeley.edu/~scheme??
ULispwww.zogotounga.net/comp/squeak/lispkit.htm??
UMB Schemewww.cs.umb.edu/~wrc/scheme??
Unlikely schememarijnhaverbeke.nl/unlikely??
Vicaremarcomaggi.github.com/vicare.htmlcompilerPOSIX / x86yes
VSCMsourceforge.net/projects/vscm??
Vx-schemecolin-smith.net/vx-scheme??
Wraith SchemeJayReynoldsFreeman.com/My/Software.htmlinterpreter + compilerMacintoshYesNo
XLISPwww.mv.com/ipusers/xlisper??
Ypsilon Schemecode.google.com/p/ypsiloninterpretermanyno






And if you carefully search on GitHub , it becomes clear that there are more options.



Following the standard in various implementations allows you to reuse code on different platforms, including for Web programming. But we must not forget that the functionality that is not included in the standard will differ with a high probability, which will lead to non-portable code.



In metal



More often in my practice I come across programming for .NET. Therefore, the solution that allows using .NET libraries and embedding the Scheme interpreter into my applications is most useful for me. Having played with different options, I stopped at IronScheme . So, at first glance, it seemed like the most advanced implementation of the R6Rs standard for .NET. But there are others about which will be written in the following articles.



IronScheme implements the sixth version of the standard R6Rs. Naturally, it has built-in functionality for interacting with the clr execution environment. Thus, right from the Scheme script we can create and manipulate .NET classes. And this is quite enough to create a full-fledged application with GUI, DB and other goodies that are available from .NET. But we are not obliged to write full programs on IronScheme. Especially as in the supplied libraries there are wrappers for a small number of standard .NET classes. Although no one bothers us to help the community.



Environment setup



  1. To start using IronScheme, download the archive from ironscheme.codeplex.com/;
  2. unpack, for example, in “Program Files (x86)”;
  3. add to the PATH environment variable "C: \ Program Files (x86) \ IronScheme \";
  4. for convenience, in the IronScheme directory, I create an “is.bat” file with the contents of “IronScheme.Console-v4.exe% 1”;
  5. Running the command IronScheme.Console-v4.exe will start the interpreter in REPL mode.


Now you can enter commands, for example "(+ 2 2)". The interpreter in the REPL mode supports auto-completion by pressing TAB, which is convenient to use as a command reference or for checking code fragments. To exit the interpreter you need to dial "(exit)".



Hello world!



By tradition, we will write and run the Hello world application. In any familiar text editor, preferably supporting Scheme, for example Sublime , create a file and save it hello-world.ss.



Contents of the hello-world.ss file:

(import (rnrs) (ironscheme) ) (displayln "Hello, world!") 


Run the command "IronScheme.Console-v4.exe hello-world.ss" as a result, we get a long-awaited inscription.

Source: https://habr.com/ru/post/267015/



All Articles