Supriya Ghosh (Editor)

CSCM (programming language)

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit
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

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 letrecs, binarys, receive, or try;.

Motivation

CSCM is aimed as an:

  • Educational tool
  • Well-established, high-quality implementation of concurrent Scheme
  • Erlang reference project
  • Joseph Wayne Norton has stated that there were a number of reasons why he started the CSCM project:.

  • He had previous experience programming in Scheme and Erlang.
  • Given his previous experience, he was interested in implementing his own Lisp.
  • In particular, he wanted to implement a Lisp in Erlang: as he was curious to see how it would run on BEAM and able to fully interact with Erlang/OTP.
  • Since helping to create the Erlang programming language, he had had the goal of making a Lisp which was specifically designed for running on the BEAM and able to fully interact with Erlang/OTP.
  • He wanted to experiment with compiling another language on top of Erlang. As such, he saw CSCM as a means of exploring this by generating Core Erlang and plugging it into the backend of the Erlang compiler.
  • He was not working with programming or Erlang at the time, so was looking for some interesting programming projects that were not too large to do in his spare time.
  • He likes implementing languages.
  • He also thought it would be a fun problem to solve, as a solution would have many parts and the problem space was quite open-ended.
  • Features

  • A language targeting Erlang Virtual Machine (BEAM)
  • Seamless Erlang integration: zero-penalty Erlang function calls (and vice versa)
  • Meta programming via macros and the homoiconicity of a Lisp
  • Shared-nothing concurrent programming via message passing (Actor model)
  • Emphasis on recursion and higher-order functions instead of side-effect-based looping
  • A full REPL for interactive development and testing (unlike Erlang's shell, the CSCM REPL supports function and macro definitions)
  • Pattern matching
  • Hot loading of code
  • Java inter-operation via JInterface and Erjang
  • 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 ebin

    Save 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:

    References

    CSCM (programming language) Wikipedia