Grits
Generally Ridiculous In Terms of Scope. One statement a line, and any keyword can be renamed while the program runs.
Davie Janeway, 2009 · Turing complete: unknown · ●○○ easy · esolangs.org
Tested with 6 known programs · Test method
Run it
The idea
Davie Janeway made Grits in 2009, an interpreted language written in Java that reached version 0.7. Every line holds one statement, and the specification warns that whitespace is included at the user's peril. A function body is cut at every space, so a string with a space in it cannot go inside a function.
Read the story
Two odd stores sit beside the variables, the meta-int and the meta-string. [name] keeps a value in the first and :$ prints it, and (name) with :^ does the same for the second. The ~ statement renames any keyword, so after ~:;print the output statement is spelled print.
The machine
| Statement | Does |
|---|---|
%name.value | Declare |
name.value | Assign |
:value | |
(a+b) {a+b} | Arithmetic on numbers; joining, cutting and matching strings |
?a.b{yes\|no} | Run one command if a equals b, else the other |
??a.b{command} | Run the command until a equals b |
!Name{c1 c2} !Name <- 9 | Define a function; call it with .x set to 9 |
->value | Return a value |
~old;new | Rename a keyword |
The specification does not say how a print ends, and this implementation ends each one with a line feed. Includes and the interactive mode are left out, since they need other files or a console, and so are files, streams and packages, which the specification only promises.
Example
The meta-int keeps a copy of a variable.
The meta-int keeps a copy of a variable.
A parameter is filled in as text, so .x becomes 9 before the line runs.
The function prints two variables. Its body has to name them, as a quoted string with a space would be cut in two.
In braces the arithmetic signs work on strings, and * reads its right side as a regex and removes every match.
Renaming the output keyword. After the second line : no longer prints.
Patterns it teaches
- Self-modifying code: a function can redefine itself, and a program can rename the language's own keywords.
Further
See also
Also in Jokes
Write your own in Run Convert a program from Grits
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: grits.
Command line
shib run grits -e '%some_int.99
[some_int]
:$'shib manual gritsSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/grits.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org