Pyret

Pyret is a new programming language designed to let learners use functional programming to build interesting and powerful programs with an economy of expression. It borrows liberally from many languages—as such, it should be instantly recognizable.

In the vein of the How to Design Programs languages, Pyret has been broken up into three different language levels.

Currently, only the first language level (Beginning Student Language) is available.

1Beginning Student Language (BSL)

1.1BSL Grammar

This is the full BSL grammar. For a gentler introduction to the language, please see the programs in the examples folder.

NOTE: braces are not part of the grammar – they are used to indicate groupings of tokens.

                      ::= *   ::= |             ::= |   |   |                     ::= |   |  struct: (?)         ::= def :         ::= fun (?): |  fun (?): *                      ::= {, }*                   ::= |                           ::= |                      ::= |   |   and |   or |  not           ::= +          ::=              ::= < | <= | = | != | >= | > | in |  not in                  ::= |  + |  - |   + |   - |   * |   / |   % |   ** |  [] |             ::= |  : |  ::                ::= .. |  ... |  .... |  ..... |  ......                   ::= empty |  True |  False |   |   |   |   |   |  () |   (?)                    ::= [ ] |  [{, }*]                ::=                  ::= |   +                ::= |  :done                      ::= if : ?                    ::= elif : ?                    ::= else: ?                    ::= test: is:                     ::= big_bang(*)              ::= = {, }*

1.1.1.1Numeric literals

There are four types of numeric literals: integers, floating point, imaginary, and inexact.

Some examples of integer literals:

 7 66 123456789123456789123456789 0o77 0xcafebabe

Floating point numbers are lexed just as they are in Racket.

 3.14 2.718 10 0.001 1000 1000 0.001

Imaginary numbers are decimal integers or floating point numbers suffixed with the letter i. (Note that a number of the form a+bi is parsed as the addition of a real number and an imaginary number with a real part of 0.)

 1i 66i 10.i 3.14i

Finally, a literal can be prefixed with 0nx, to indicate that it is inexact. (Here, a complex number such as 0nx2+3i parses as the inexact number 2+3i, NOT the inexact number 2 + 3i).

 0nx1.0 0nx2+3i 0nx4i
1.1.1.2String literals

String literals are read in exactly the same manner as they are in Racket. See the Racket reference for more information.

1.2Pre-defined variables

 empty : is_empty

The empty list.

 True : is_true

The boolean value corresponding to truth.

 False : is_false

The boolean value corresponding to falsehood.

1.3Template Variables

 ..
A placeholder for indicating that a definition is a template
 ...
A placeholder for indicating that a definition is a template
 ....
A placeholder for indicating that a definition is a template
 .....
A placeholder for indicating that a definition is a template
 ......
A placeholder for indicating that a definition is a template