Tg
Postfix on the outside, a lazy functional language underneath.
SteloKim, 2008 · Turing complete: no · ●●○ moderate · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
SteloKim made Tg in 2008. A program is written in postfix, like Forth, but nothing runs while it is read. Each operator takes its operands off the stack and leaves an expression, and the compiler turns the finished expression into OCaml. Evaluation is lazy, so an operand that is never needed is never computed. In 2 0 / 3 cdr the division by zero is thrown away unseen. Types are inferred before anything runs, so a program that adds a string to a number prints nothing at all.
Read the story
The specification calls Tg incomplete. It has functions of one parameter but no way to loop or recurse, so every program stops.
The machine
| Code | Does |
|---|---|
3 3.0 "text" | An int, a float, a string |
a b + - * / | Int arithmetic |
a b +. -. *. /. | Float arithmetic |
a b = | True if they are equal |
a b car a b cdr | Gives a, or gives b |
c t e ? | Gives t if c is true, else e |
a display newline | Print a; print a line break |
rand | A float from 0 to 1 |
a b ; | Do a, then b |
arg body x \ | The function of x applied to arg |
Lines are joined with ;, so a program of several lines ends most of them with ;;, one to finish the line and one to join it to the lines before.
Example
A function of x that adds y, applied to 3, inside a function of y applied to 4.
A function of x that adds y, applied to 3, inside a function of y applied to 4.
A greeting. The body prints "Hello, ", then str, then "!" and a line break, and str \ applies it to "Tg".
Further
Ideas it shows
See also
Also in Functional and concatenative
Write your own in Run Convert a program from Tg
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: tg.
Command line
shib run tg -e '10 20 + display newline;'shib manual tgSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/tg.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org