esolang

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

Expected: 99

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

StatementDoes
%name.valueDeclare
name.valueAssign
:valuePrint
(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 <- 9Define a function; call it with .x set to 9
->valueReturn a value
~old;newRename 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.

Expected: 81

The function prints two variables. Its body has to name them, as a quoted string with a space would be cut in two.

Expected: 100 Hello, World!

In braces the arithmetic signs work on strings, and * reads its right side as a regex and removes every match.

Expected: Hello

Renaming the output keyword. After the second line : no longer prints.

Expected: Regular Output Symbol Redefined Output Symbol

Patterns it teaches

  • Self-modifying code: a function can redefine itself, and a program can rename the language's own keywords.

Further

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 grits

Source

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