Designed by Joseph Wayne Norton First appeared 2013 | Developer Joseph Wayne Norton Typing discipline dynamic, strong | |
Paradigm multi-paradigm, concurrent, functional Stable release v0.5.4 / 12 May 2014 (2014-05-12) |
CSCM (The Concurrent Schemer) is an implementation of the Scheme programming language built on top of the Erlang virtual machine (BEAM). CSCM combines the sequential programming model of Scheme with the concurrent, distributed, and fault-tolerant programming model of Erlang.
Contents
- Initial release
- Motivation
- Features
- Symbolic expressions S expressions
- Lists
- Operators
- Lambda expressions and function definition
- Start up
- Pattern matching
- List comprehensions
- Guards
- consing in function heads
- Matching records in function heads
- Receiving messages
- Erlang interoperability
- Functional paradigm
- Concurrency
- References
By leveraging the Erlang language, CSCM can target a concise, precise specification of the Scheme language. Consequently, by leveraging the Erlang VM, CSCM can target a performant, robust implementation of the Scheme language. The default language is Scheme R7RS and the default virtual machine is Erlang/OTP 17 or higher. Scheme R5RS is available as a Scheme library.
CSCM builds on top of Erlang in order to provide a Scheme syntax for writing distributed, fault-tolerant, soft real-time, non-stop applications. CSCM also extends Erlang to support meta-programming with hygenic macros and an improved developer experience with a feature-rich REPL.
Initial release
Joseph Wayne Norton announced the first release of CSCM on GitHub in March 2013. This release of CSCM was very limited: it did not handle recursive letrec
s, binary
s, receive
, or try
;.
Motivation
CSCM is aimed as an:
Joseph Wayne Norton has stated that there were a number of reasons why he started the CSCM project:.
Features
Symbolic expressions (S-expressions)
Being a Scheme, CSCM is an expression-oriented language. Unlike non-homoiconic programming languages, Lisps make no or little syntactic distinction between "expressions" and "statements": all code and data are written as expressions. CSCM brought homoiconicity to the Erlang VM.
Lists
The cons function actually accepts any two values, not just a list for the second argument. When the second argument is not empty and not itself produced by cons, the result prints in a special way. The two values joined with cons are printed between parentheses, but with a dot (i.e., a period surrounded by whitespace) in between:
> (cons 1 2) (1 . 2) > (cons "banana" "split") ("banana" . "split")Thus, a value produced by cons is not always a list. In general, the result of cons is a pair. The more traditional name for the cons? function is pair?
Operators
The Erlang operators are used in the same way. The expression
evaluates to 42. Unlike functions in Erlang, arithmetic operators in scheme are variadic (or n-ary), able to take any number of arguments.
Lambda expressions and function definition
CSCM has lambda, just like scheme. It also, however, has lambda-match to account for Erlang's pattern-matching capabilities in anonymous function calls.
Start up
Start the Erlang shell.
erl -pa ./deps/parse-tools/ebin -pa ebinSave the "hello word" program as an Erlang string.
Str = "(define hello-world (lambda () (display "Hello World!")))
".
Create an empty Scheme environment.
Env = scmi_env:the_empty().Create and register a native Erlang function as a simple implementation for the Scheme display library procedure. The Erlang function writes the given arguments to stdout as Erlang terms and simply returns a Scheme #false to the caller.
Parse and evaluate the "hello world" program.
Call the Scheme "hello-world" procedure and show the Scheme return value in the Erlang shell.
This section does not represent a complete comparison between Erlang and CSCM, but should give a taste.
Pattern matching
Erlang:
CSCM:
The basic form of pattern matching expression is:
(match exp [pat body] ...)
List comprehensions
Erlang:
CSCM:
Or idiomatic functional style:
Guards
Erlang:
CSCM:
cons'ing in function heads
Erlang:
CSCM:
or using a ``cons`` literal instead of the constructor form:
Matching records in function heads
Erlang:
CSCM:
Receiving messages
Erlang:
CSCM:
or CSCM:
Erlang interoperability
Calls to Erlang functions take the form (<module>:<function> <arg1> ... <argn>):
Functional paradigm
Using recursion to define the Ackermann function:
Composing functions:
Concurrency
Message-passing with Erlang's light-weight "processes":
Multiple simultaneous HTTP requests: