Lunar Programming Language

by David A. Moon
January 2017 - January 2018



Basic Data Types

Everything

The everything class has every datum as a member and every class as a subclass. This is the "top" class ⊤.

Nothing

The nothing class has no datum as a member and every class as a superclass. This is the "bottom" class ⊥.

Boolean

The boolean class has just two instances, true and false. For convenience, each instance is also a singleton class. Thus false is a type whose only member is false itself.

These classes could have been defined by:

abstract: sealed:
defclass boolean

singleton: intrinsic:
defclass true boolean

singleton: intrinsic:
defclass false boolean

Name

The name class comprises what Lisp calls "symbols." A name has a spelling which is any string. There is only one name with any given spelling, ignoring alphabetic case, so names can be compared with eq. = on names is the same as eq.

The class could have been defined by:

sealed: constant:
defclass name constructor: _make_name(spelling string)

def name(spelling string)
  ;; if a name with that spelling already exists, return it
  ;; otherwise call _make_name, intern it, and return the result

def name(spelling name)
  name(spelling.spelling)

;; name.spelling returns the name's spelling string.

At compile time there is a name_in_context subclass of name used by hygienic macros. There is only one name_in_context with any given spelling in any given context, so again = is the same as eq.

The same_spelling? function is equality of names ignoring context. See Name In Context for name_in_context and related methods.

Character

The character class has all Unicode characters as members. It has one constant slot code, which contains the character code. The constructor takes one parameter, the character code. It could have been defined by:

sealed: constant: intrinsic:
defclass character(code 0..1048575)

Number

The number class is a superclass of integer and float.

Integer

The integer class represents integral numbers. The class is closed under the operations + - * / mod ^ & | ~ and the result is always the mathematically correct value. If that value cannot be represented, typically due to memory exhaustion, an error exception occurs. These operators never return a mathematically incorrect answer.

The division operator / produces an integer result. For all x and all non-zero y, x = x/y + x mod y.

The division operator / and the remainder operator mod round towards zero, so 4/3 = 1, 5 mod 3 = 2, -4/3 = -1, and -5 mod 3 = -2. For negative arguments, mod is not the usual modulus operator.

The right-associative ^ operator is exponentiation.

The bit-wise logical operators & | ~ use twos-complement representation for negative numbers.

The integer pseudo-constructor has the following methods:

def integer(x integer) x    ; already an integer

def integer(x float, named: round = #truncate set(#up, #down, #nearest, #truncate))
  ;; convert float to integer

def integer(x sequence[character], named: base = 10 2..36)
  ;; parse decimal or other-base representation of integer

Float

The float class represents 64-bit floating-point numbers. The class is closed under the operations + - * / mod and the result is always as defined by IEEE 754.

The float pseudo-constructor has the following methods:

def float(x float) x   ; already a float

def float(x integer)   ; convert integer to floating point

def float(x sequence[character])
  ;; parse decimal representation of floating point number

Type

The abstract type class has all types as members. A type is a set of data which may not be finite or enumerable, but membership can be tested. Every datum is either a member of the type or not a member of the type.

Type membership is constant with a special exception for bundles. See Bundles

The operations on types are:

(x everything) in (t type) => boolean
True if x is a member of t

(t1 type) <= (t2 type) => boolean
True if every member of t1 must also be a member of t2, i.e. t1 is a subtype of t2 or they are the same type.

(t1 type) = (t2 type) => boolean
True if t1 and t2 must have the same members, i.e. they are the same type.

disjoint?(t1 type, t2 type) => boolean
True if no object can be a member of both t1 and t2.

union(t1 type, more_types type...) => type
Every member of a type union is a member of at least one of the given types. Also accessible via the | operator.

intersection(t1 type, more_types type...) => type
Every member of a type intersection is a member of all of the given types. Also accessible via the & operator.

Class

The type class is a subclass of type that defines the structure of its direct members and supports inheritance.

class(x everything) => class
This sealed method of the class function bundle returns the class of its sole parameter. This is distince from the class constructor, which requires multiple actual parameters.

Range

The type range is a subclass of type that is a range of integers or characters. A range is also a sequence; unlike most other types it is enumerable. See Ranges

Set

The type set is a subclass of sequence that is a set of data with no duplicates.

The type constant_set is a subclass of set and of type that is a constant set of specific data. A constant_set is also a sequence; unlike most other types it is enumerable. See Sets

The type set! is a variable set and is a subclass of set and of sequence! but not a subclass of type.

Union

The type type_union is a subclass of type that is a union of two or more types. The union constructor returns a type_union when all actual parameters are types and the result cannot be simplified to a single type. The | operator invokes the union constructor when both actual parameters are types or sets.

A member of a type_union is a subtype of the union.

Intersection

The type type_intersection is a subclass of type that is an intersection of two or more types. The intersection constructor returns a type_intersection when all actual parameters are types and the result cannot be simplified to a single type. The & operator invokes the intersection constructor when both actual parameters are types or sets.

A member of a type_intersection is a supertype of the intersection.

Function

The type function contains objects that can be invoked with actual parameters.

Method

The type method contains objects that are part of a function and can be invoked with actual parameters through that function or directly. It is a subtype of function.


Previous page   Table of Contents   Next page



Creative Commons License
Lunar by David A. Moon is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
Please inform me if you find this useful, or use any of the ideas embedded in it.
Comments and criticisms to dave underscore moon atsign alum dot mit dot edu.