Skip to content
tré – Lisp transpiler – compiles to Common Lisp (SBCL), JavaScript and PHP.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
environment
examples
makefiles
tests
CONTRIB.md
EXAMPLES.md
LICENSE
NEWS
README.md
WISHLIST.md
boot-common.lisp
make.sh
tre

README.md

The tré programming language

Overview

tré compiles its own dialect of the Lisp programming language to JavaScript or PHP.

External resources

Applications

phitamine demo shop

Shows how a PHP shop can be done with phitamine.

phitamine

A framework to create PHP-only web sites with tré. centralservices provides a couple of widgets.

bender

A UNIX command line 6502-CPU assembler.

Modules

JavaScript DOM and utilities

Localisation

PHP utilities

PHP MySQL interface

Utilities shared across platforms

SQL clause generators

Lisp Markup Language utilities

Multitrack timetable + JS DOM graphics

Examples

JavaScript 3D canvas

Software-rendered 3D, playing a video on a rotating plane.

Building and installing

Make sure you have sbcl (Steel Bank Common Lisp) installed. Then run:

./make.sh boot
./make.sh install

The installed binary is named "tre" in /usr/local/bin. It takes an optional pathname of a source file to compile and execute. If none is specified, it'll prompt you for expressions to execute.

Syntax

tré comes with a lot of syntactical sugar to get rid of those embarrassing braces and to keep things snappy.

No LAMBDA symbol required

The LAMBDA symbol may be safely omitted when defining functions. Influenced by Arc.

 #'(lambda (args)
     function-body)

can be written:

 #'((args)
     function-body)

General abbreviations

Inspired by the C syntax these are synonyms for what you would expect from Common Lisp. The original names are, most of the time, still there.

  • == instead of =
  • = instead of SETF
  • ? instead of IF
  • & instead of AND
  • | instead of OR
  • / instead of DIV

Due to name collision the original meaning of '=' is gone in favour of '=='.

There are also abbreviations for some anaphoric macros inspired by Arc (which are still around):

  • != instead of ALET (Arc)
  • !? instead of AIF (Arc)
  • !@ instead of ADOLIST (Arc) (See also '@'.)

Dot instead of CONS

(. a b)

is the same as

(cons a b)

Dots instead of CAR or CDR

Probably inspired by some COBOL manual, tré first of all takes the edge off by removing the zoo of CAR, CDR and related expressions. Instead of doing "(car x)" you are now invited to use "x." instead. The equivalent for "(cdr x)" would be ".x". You can also combine the two dots, so "(cadr x)" is ".x." for the second element. To access the third element "(caddr x)" just do "..x.".

x.      ; (car x)
.x      ; (cdr x)
.x.     ; (cadr x)
..x.    ; (caddr x)
..x..   ; (caaddr x)

Square brackets [] for anonymous functions

Inspired by Arc

[expr]

[(expr1)
 (expr2)]

is the equivalent of

 #'((_)
      (expr))

 #'((_)
      (expr1)
      (expr2))

If 'expr' starts with a symbol, it is wrapped into a list to form an expression.

NOT IMPLEMENTED YET: Tré also lets you make your own argument definitions. To roll your own basically end them with a syntax-violating closing round bracket:

[body]              #'((_) body)
[) body]            #'(() body)
[x) body]           #'((x) body)
[x &rest y) body]   #'((x rest y) body)

Curly brackets {} to make JSON objects or instead of PROGN

If you open an expression with a curly brace it'll become a literal (JSON) object if the first element is a keyword or a string. Then the argument is grouped into key/value pairs. Otherwise it'll become a PROGN.

; Use as PROGN (first element is not a string or keyword).
(| x
   {(do-something)
    (do-something-else)}

; Use as literal object.
{:item1    "1"
 "item2"   "2"
 :oh-no    3}

Note that keyword keys will be translated into camel notation. ':oh-no' will become 'ohNo'.

At sign @ instead of DOLIST or FILTER

; Use as FILTER.
(@ #'filter-function x)
(@ (i x)
  (filter-function/return-value-lost i))

Comma for anonymous macros

These are QUASIQUOTEs aka commas outside BACKQUOTEs aka backticks aka '`'. They are evaluated before the standard macro expansion pass.

Some exciting example missing here.

Comma for dynamic SLOT-VALUE access (NOT IMPLEMENTED)

When working with JSON data for example lots of SLOT-VALUE expressions can spoil the fun. Here's an example:

(slot-value slot name)  ; Old style.
slot.,name              ; New style.
You can’t perform that action at this time.