web/contents/home.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
<article>
<h2>Welcome to the <em>hex</em> programming language</h2>
<p><strong>hex</strong> is a tiny, minimalist, concatenative, stack-based and slightly-esoteric programming language
that can run on many platforms (including <a href="/play">the browser</a>) and can be used as an embedded
language, to create shell scripts, or simply to learn more about concatenative programming.</p>
<p>Its syntax is heavily inspired by the <a href="https://min-lang.org" target="_blank">min</a> programming
language, and features
space-separated tokens, no unnecessary punctuation characters, and round brackets to delimit lists.</p>
<h3>Features</h3>
<ul>
<li>Support <strong>32bit integers</strong>, <em>written only in hexadecimal format</em>, both positive and
negative (represented via <a href="https://en.wikipedia.org/wiki/Two%27s_complement" target="_blank">two's
complement</a>),
<strong>strings</strong>, and <strong>quotations</strong> (lists).
</li>
<li><strong>64 native symbols</strong> 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.</li>
<li>Fully <strong>homoiconic</strong> (everything is data).</li>
<li>Includes a simple <strong>REPL</strong>.</li>
<li>Includes an integrated <strong>help system</strong>.</li>
<li>Implemented as <strong>a single <a href="https://github.com/h3rald/hex/blob/master/src/hex.c" target="_blank">.c
file</a> and a
single <a href="https://github.com/h3rald/hex/blob/master/src/hex.h" target="_blank">.h file</a></strong>,
making it easier
to
embed in other programs and port to different platforms.</li>
</ul>
<h3>Example</h3>
<p> The following code executes the <em>ls</em> command, retrieves the files returned in standard output, and stores
them
inside a quotation that is then printed:</p>
<pre><code>"ls" run 0x1 get "\n" split puts</code></pre>
<p>Note that <strong>no variable is used in the code above</strong>! Let's break it down:</p>
<ul>
<li>The string <code>"ls"</code> is pushed on the stack.</li>
<li>The {{sym-run}} symbol is executed, which runs the command <code>ls</code> and pushes quotation on the
stack
containing three elements: the return code of the program, its standard output, and its standard error.</li>
<li>The integer <code>0x1</code> is pushed on the stack.</li>
<li>The {{sym-get}} symbol is executed, which retrieves the second element of the quotation (the standard
output).</li>
<li>The string <code>"\n"</code> is pushed on the stack.</li>
<li>The {{sym-split}} symbol is executed, which splits the string using the newline character as a
separator.</li>
<li>The {{sym-puts}} symbol is executed, which prints the quotation on the stack.</li>
</ul>
</article>
|