git @ Cat's Eye Technologies Decoy / fd9e972
fd9e972

Tree @fd9e972 (Download .tar.gz)

Decoy

Work in progress

Decoy is a simple functional language with a syntax derived from R5RS Scheme and semantics derived from R5RS Scheme.

But it's not Scheme. Thus the name.

It's also not a general-purpose language. For more information, see the Decoy Language Definition.

Quick Start

Decoy has a reference interpreter, which is written in Lua 5.1.

  • Make sure Lua 5.1 is installed
  • Clone this repo
  • Change directory to the repo's root directory
  • Run ./test.sh to run the test suite.
  • Run ./bin/decoy eval eg/foo.scm to evaluate a Decoy module.
  • Run ./bin/decoy compile eg/foo.scm to compile a Decoy module to JavaScript.

Design Considerations

Having pure functions that transform an system state (plus possibly some input parameters) into a "next system state" (plus possibly some output events) is a really spiffy way to define and implement things like programming languages and user interfaces.

In programming languages they call this small-step operational semantics. In JavaScript web development they call these functions reducers. There are a number of other variations on this theme out there.

I wanted a language for writing these state-transformation functions in. Since the functions themselves are pure (have no side effects), the language should support (or even better, enforce) that. (Thus, no set!.)

It should also be simple to implement, and straightforward to compile to (or otherwise interoperate with) other more conventional languages such as JavaScript. (Thus the simplified type system, and lack of tail recursion.)

Finally, it shouldn't innovate too much in the areas of syntax or semantics, to improve learnability and transferrability, if not strict compatibility. (Thus the significant Scheme borrowings, without actually being Scheme.)

Comparison to Other Languages

Decoy is not Scheme

Lots of things are missing:

  • Cons cells aren't mutable
  • There's no tail recursion
  • There's no vectors
  • There's no numeric tower
  • There's no quote or quasiquote notation
  • There's no character or boolean constants
  • There's no macros
  • define can only be used at top-level
  • There's no call-with-current-continuation or dynamic-wind
  • There's no ports
  • There's no support for SRFIs

All the same, the set of programs that are both R5RS Scheme programs and Decoy programs ought to be fairly large.

Some things are added:

  • A module system of sorts
  • Some libraries, supplied as modules in this system

Again, these would not be too difficult to support in Scheme by means of some support functions and/or macros.

Relation to Pixley

Pixley is a much earlier project by the same author to define a minimal subset of Scheme in which a self-interpreter could be written. While Decoy has some similarities to Pixley, Decoy is generally a richer language, in which there are more data types (such as numbers), more standard procedures (such as list), and a module system. There are also no plans to implement a Decoy interpreter in Decoy.

Relation to Robin

Robin is an earlier project by the same author.

TBW.

TODO

Compiler

  • import statements
  • more thorough name mangling (how can we make this predictable for interop?)
  • "super mangling": translate + => add, etc.
  • tests for compiler!

Modules

  • Some way to map modules names to (implementation domain) module names
  • Import (getThing as get-thing) ... ?
  • Test that circular imports don't loop
  • Test that import diamonds are OK
  • --module-dir for now, not path

Forms

In Scheme

  • = -- procedure; this only works on numbers
  • map -- library procedure
  • length -- library procedure
  • append -- library procedure
  • (string-length string) procedure
  • (string-ref string k) procedure
  • (string<? string1 string2) library procedure
  • (string>? string1 string2) library procedure
  • (string<=? string1 string2) library procedure

Not in Scheme

  • fold -- this is not in Scheme or Chicken by default
  • assert -- this is in Chicken by default too -- note this is a macro

Aspirational

  • Interned strings and modules? Hash-consing, even?
  • Tracebacks, or at least line/column, or at least "in function..."
  • Module path should be like LUA_PATH with the patterns