The CaPriCon Scripting Language Reference
All the basic words are described below.
The environment of the interpreter consists mostly of a stack of values, that can be manipulated with the following words.
Duplicates the top element, or the nth top element of the stack.
Swaps the top element of the stack with the second, or the nth element.
Shifts the nth element towards the top, or shaft the top to the nth place.
Pops the top element, or the nth top element, off the stack.
Clears the stack.
Pushes the current stack, as a list, on top of the current stack. In the second case, sets the top element of the stack as the new stack.
Picks the i-between-nth element of the stack, and discards all others. Can be useful for implementing arbitrary switch-like control-flow.
Names and variables
Sets the value of a variable.
def: in an environment where is associated with the variable named .
Examples :(x + y) * y = 70; y = 7 ; x = 3
The inverse of
def. Given the name of a variable at the top of the stack, this function produces the value of the corresponding variable in the current environment.
Pushes the active dictionary, that contains all defined variables, on top of the stack. In the second case, make the top of the stack the current dictionary, redefining all variables at once.
A more flexible version of
$, where the environment is specified explicitly as a second argument (for example, from calling
Executes the value at the top of the stack, as if it were the meaning of a word. To illustrate, given a function,
'f $ execis equivalent to
fitself. That is, evaluating a symbol is no different than looking it up in the current dictionary, and
executing its value.
Puts a “list beginning” (LB) marker on the stack
Creates a list of the elements on the stack until the next “list beginning” marker, and pushes it on the remaining stack.
Iterates over each element of its second argument, pushing it on the stack and running its second argument afterward.
Values: 1 2 3
Create a list of numbers from 0 to , being the top element of the stack.
Simple integer arithmetic
Performs the usual binary arithmetic operation on the top two elements of the stack, and replaces them with the result.
Computes the sign of the top stack element. If the sign is negative, produces , if positive produces , otherwise produces .
Much like the
sprintf()function in C, produces a string which may contain textual representations of various other values.
1: Some text
Tries to convert the top stack element to an integer, if possible.
Interacting with the environment
Exits the interpreter, immediately and unconditionally.
Print the string at the top of the stack into the current document.
Opens an external source file, and pushes a quote on the stack with its contents.
Given a resource name and a quote, does one of two things :
- if the resource already exists, try to open it as a CaPriCon object, ignoring the quote
- otherwise, run the quote and store its result in the resource for future use
After the builtin has run, the contents of the requested object can be found at the top of the stack.
Given a resource name and a quote, executes the quote, redirecting its output to the resource.
Pushes the empty dictionary onto the stack.
Given a dictionary
d, a key
kand a value
v, inserts the value
d, then pushes the result on the stack.
The reverse of
insert. Given a dictionary
dand a key
k, produce a dictionary
d'that is identical to
d, without any association for
Given a dictionary
d, pushes a list of all of
d’s keys onto the stack.
Constructing typed terms
Produces a universe.
Given a variable name, that exists in the current type context, produces that variable.
Given a function
f, and a term
x, produces the term
Abstracts the last hypothesis in context for the term at the top of the stack. That hypothesis is abstracted repectively as a lambda-abstraction, or a product.
Produces an inductive projection to a higher universe for the term at the top of the stack, if that term is of an inductive type.
Given a combinatorial type (a type without free variables) and an associated tag, produce an axiom with that tag, that can serve as a proof of the given type.
Analysing typed terms
Computes the type of the term at the top of the stack.
Given a quote for each possible shape, and a term, executes the corresponding quote :
Extract the term at the top of the stack into an abstract algebraic representation, suitable for the production of foreign functional code, such as OCaml or Haskell.
Managing the type context
Given a type and a name , adds a new hypothesis of type to the context. Alternately, you can give a second hypothesis name , in which case the new hypothesis will be introduced before .
Clears the last hypothesis from the context. Every term that references that hypothesis is abstracted either as a lambda-expression, or as a product, depending on the variant that was called.
Renames a hypothesis. This function takes two parameters : a hypothesis name, and the new name to give it.
Given a hypothesis name, and a term of the same type as that hypothesis, remove that hypothesis from the context by substituting all its occurences by the given term.
Pushes a list of all the hypotheses’ names in context, from most recent to the oldest.