Welcome to the hex programming language
hex is a tiny, minimalist, concatenative, stack-based and slightly-esoteric programming language that can run on many platforms (including modern browsers) and can be used as an embedded language, to create shell scripts, or simply to learn more about concatenative programming.
Its syntax is heavily inspired by the min programming language, and features space-separated tokens, no unnecessary punctuation characters, and round brackets to delimit lists.
Features
- Support 32bit integers, written only in hexadecimal format, both positive and negative (represented via two's complement), strings, and quotations (lists).
- 64 native symbols implementing simple arithmetic, boolean logic, bitwise operations, comparison of integers, read/write from/to stdin/stdout/stderr, read and write files, execute external processes, work with quotations and strings, create and delete user symbols (variables), error handling, and manipulate the stack.
- Fully homoiconic (everything is data).
- Implements a simple virtual machine with a bytecode compiler and interpreter.
- Includes a simple REPL.
- Includes an integrated help system.
- Distributable through one single, amalgamated C file, making it easier to embed in other programs and port to different platforms.
Example
The following code executes the ls command, retrieves the files returned in standard output, and stores them inside a quotation that is then printed:
"ls" run 0x1 get "\n" split puts
Note that no variable is used in the code above! Let's break it down:
- The string
"ls"
is pushed on the stack. - The run symbol is executed, which runs the command
ls
and pushes quotation on the stack containing three elements: the return code of the program, its standard output, and its standard error. - The integer
0x1
is pushed on the stack. - The get symbol is executed, which retrieves the second element of the quotation (the standard output).
- The string
"\n"
is pushed on the stack. - The split symbol is executed, which splits the string using the newline character as a separator.
- The puts symbol is executed, which prints the quotation on the stack.