HTPL

From Esolang
Jump to navigation Jump to search

The Hypertext Programming Language is best described as a strict syntactical subset of HTML. Its main purpose is to provide a way to claim that:

HTML is a programming language (if it is interpreted as HTPL).

History

The HTPL is still a work in progress. For any suggestions or discussions, please visit the talk page: Talk:HTPL

Datatypes

HTPL is a dynamically typed language. As such, it has the primitive data types:

  • String
  • Number
  • Array
  • Boolean

Syntax

As a subset of HTML, HTPL code should always be able to be interpreted as 'correct' HTML code. The only difference is the enclosing tag not as <html> but as <htpl>. The rest of HTPL's syntax is defined as following:

HTPL Description
<var id="foo">42</var> Declares a single variable called foo with the numeric value 42. Variables can only be declared once.
<table><td>1</td><td>2</td></table> Declares a array with the values [1, 2]
<p>Hello</p> Prints the word "Hello"
<input id="bar" /> Reads a byte from the input and saves in in the variable bar
<button value="{foo}"><p>{foo}</p></button> Prints the variable foo, if foo is true. The code inside the <button>-tag is only executed if value is true
<select id="x" name="{foo}"></select> Declares a switch statement, in which the content of name is set to a variable with name of id (the id-attribute is optional).
<option value="0"><p>A</p></option> Inside a <select>-tag, if the id is equal to the <option>'s value, the code is executed.
<ol id="i" value="0"><p>{i}</p></ol> Prints an infinite amount of ever increasing numbers. <ol> declares an infinite loop that is to be breaked from explicitly. With each successfully executed completion the value of the variable with the name of the id is increased. The start value can be set manually with the value attribute and has to be a number.
<li value="69"><p>Nice</p></li> Inside a <ol>-tag, if the iterator has the value 69, print "Nice".
<br/> Breaks from the current function, loop, code-block. If used in the main <htpl>-tag, the program is terminated.
<div id="buzz">...</div> Declares the function called buzz. Parameters can be accessed via the variables $0, $1, $2 ...
<a href="#buzz">1</a> Calls the function buzz with one parameter with the value 1.

Examples

Hello World

<htpl>
  <p>Hello World!</p>
  <br/>
</htpl>

Related