Lapis Tutorial for version 0.9

By Zack Smith, copyright © 2005, all rights reserved.

Introduction

The Lapis language is an object-oriented stack language that is still in its early stages of development.

The Stack

If you are not familiar with stack languages, they work very simply. All computations are done on a stack. You still have variables and such, but if you want to work with them, you must "push" them onto the stack, perform any operation on them, and if need be, "pop" them off the stack again. You may be familiar with this concept from programming classes: Stack based computations use the postfix notation, as opposed to the more commonplace infix notation.

Key acronyms:
	TOS = top item on the stack
	NOS = next item on the stack

For instance, consider the following postfix expression:

53 11 - ++ 2 * First, thus puts two items on the stack: 53, and on top of that, 11. The "-" subtracts 11 from 33 and replaces both with the difference, which is 42. The "++" operator then increments that value to 43, the 2 is pushed and we multiply 43 and 2 to get 86.

If you then want to write the result to the output i.e. send it to the web browser, you use ".", which removes the item printed from the stack, or you can say "write", which retains the TOS.

Another example: Suppose you want to create an RGB image that is 320 by 240. You do this:

320 240 Image which puts the image on the top of the stack for you to then do more work with.

Note! Image is the name of a class. To create a new instance of any class, one merely needs express the class's name.

Data types

Basic stack operations

I/O functionality

System operations

HTML functionality

String manipulations operations

Still more to add.

Arithmetic and bitwise operations

These work on integers and reals, although the + method also works on strings.

Boolean operations

Advanced math functions and constants

These work primarily on reals.

Constants

Matrix operations

Hardly begun.

NameValue operations

A NameValue is an ordered name-value pairing.

Array operations

Image manipulation

Example:

300 200 Image 
	( 20 10 ) moveto
	( "blue" getcolor ) setcolor
	( 100 100 ) lineto
	( 15 3 * 190 ) lineto
	( Font ( "rl" ) loadconsolefont ) setfont
print
drop

Variables

Example:

/total_apples 100 = /total_apples total_apples -- = total_apples print ~total_apples

This will define the variable total_apples to 100, then redefine it to the value 99 (we push its value and decrement that), then print the value.

Another example:

/myimage 320 240 Image = myimage ( 100 100 ) moveto ( 300 200 ) lineto print drop

This defines variable myimage to contain an RGB image that is 320 by 240. To draw a line in the image we push it onto the stack and when we're done, we "drop" or discard the image on the top, which is actually just a reference to the original.

Classes

Currently all classes are preset and unchangeable.

Rule: class names must begin with an uppercase letter.

Program control

Not implemented yet.

Functions

Not implemented yet.

Database access

Not implemented yet.