Grass

From Esolang
Jump to navigation Jump to search

Grass is a functional grass-planting programming language. Its unique characteristic is that it is said to be easy to slip into ASCII art.

Grass is based on lambda calculus, and the program consists of a list of abstractions and applications of functions, using only the characters W, w, and v.

Despite the language is said to have functional paradigm, its actual specifications show it's somewhat procedural paradigm.

Overview

The following six characters are valid characters for Grass, and others are ignored:W, w, v, , , and . The three full-width characters are semantically identical to each corresponding half-width character. A program in Grass is considered to be a sequence of functions. Tokens beginning with W are application and those beginning with w are abstraction. v separates tokens.

Grass has a SECD machine as a virtual machine. Its environment is initialized with four primitive functions: Out, Succ, integer 119 (or character 'w'), and In.

The Out function takes one argument, an integer, to output it as an ASCII character. It must be an integer or else the program will abort. The Succ function takes one argument, an integer , to return . Integer can be both an argument of a function and a function itself. As a function, it takes one argument to return if the integer value and that of its argument are equal, as a Church boolean ( and for true and false respectively). The In function takes one argument, reads a character from stdin, and returns it on success or returns the argument instead if EOF is encountered.

Ambiguity

If you declare a function with no applications, for example wv or we, the function returns its last argument.

Examples

The following code prints a single 'w'.

wWWwwww

which is roughly equivalent to the following Haskell-like code:

main = do
  let f1 = input
  let f2 = 119
  let f3 = next
  let f4 = output
  let f5 v5 = do
    let v6 = f4 f2
    return v6
  return f5 f5

The following code prints 'w' forever.

無限に草植えときますねwWWwwwwWWww

which is roughly equivalent to the following code (note that inside function f5, v6 does not do something with function to output that but you cannot skip that or the program would never output; this is treated as a procedural language, not as a pure function programming language):

main = do
  let f1 = input
  let f2 = 119
  let f3 = next
  let f4 = output
  let f5 v5 = do
    let v6 = f4 f2
    let v7 = v5 v5
    return v7
  return f5 f5

Said to implement fixed-point combinator (Y combinator); idk why it works:

YコンビネータwwWWwwWwwvちょwwWWWwWWWwvおまwWWwWwv

which looked like to be translated to following:

A = \f->\g->f f g
B = \f->\g->f (A g)
C = \f->(B f) (B f)
main = C C

The following code calculates and prints the result as a number of 'w's.

wwWWwv
wwwwWWWwwWwwWWWWWWwwwwWwwv
wWWwwwWwwwwWwwwwwwWwwwwwwwww

which is roughly equivalent to the following code:

main = do
  let f1 = input
  let f2 = 119
  let f3 = next
  let f4 = output
  let f5 v5 v6 = do
    let v7 = v5 v6
    return v7
  let f6 v6 v7 v8 v9 = do
    let v10 = v7 v8
    let v11 = v10 v9
    let v12 = v6 v8
    let v13 = v12 v11
    return v13
  let f7 v7 = do
    let v8 = f6 f5
    let v9 = v8 f5
    let v10 = v9 f4
    let v11 = v10 f2
    return v11
  return f7

Prints "はいはいわろすわろす" in Shift-JIS (which is, in binary, "\x82\xcd\x82\xa2\x82\xcd\x82\xa2\x82\xed\x82\xeb\x82\xb7\x82\xed\x82\xeb\x82\xb7"):

wwwwvwvwwWWwvwwWwwvwwwwWWWwwWwwWWWWWWwwwwWw
wvwWWwWwwvwWWWwwwwwWwwwwwwWWwWWWwWWWWWWwW
WWWWWWWwwwWwwWWWWWWWWWWwWwwwwwWWWWWWWW
WWWwwwwwWWWWWWWWWWWWwwwwWWWWWWWWWWWWW
wwwWWWWWWWWWWWWWWwwwWWWWWWWWWWWWWWWwW
WWWWWWWWWWWWWWWWWwwwWwwwwwwwwwwwwwwWWWW
WWWWWWWWWWWWWWWwwwwwwwwWwwWWWWWWWWWWW
WWWWWWWWWWWWWwwwwwwwwwwwwwwwwwwwwwwwwWwwww
wwwwwwwwwwwwwwwww             wwwwwwwwWWwwwwwww
wwwwwwwwwwwwwwwww          は   wwwwwWWWWWWWWWW
WWWWWwWwwwWWWW    わ   い   WWWWWWWwwwWwwWW
WWWWWWWWWWwwww    ろ   は    wWwwwwwwwWWWWWWW
WWWWWWWWWWwwww    す   い   wwwWwwWWWWWWWWW
WWWWWWWWWwwwww     わ       wwwwWwwWWWWWWWW
WWWWWWWWWWWWW    ろ       WWWWWWWWWwwwwww
wwwwwWwwWWWWWWW    す       WWWWWWWWWwwwwww
wwwwwwwWwwwwwwwww             wwwwwwWWWWWWWWW
WWWWWWWWwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
wwwwwwWwwwwwwwwwwwwwwWWwwwwwwwwwWWWwwWWWWwww
wwwwwwwwwwwwWWWWWwwWWWWWWwwwwWWWWWWWwwWWW
WWWWWwwwwWWWWWWWWWwwWWWWWWWWWWwwwwwwwww
wwwwWWWWWWWWWWWWWWWWWWWWWWWWWWWWwwwwww
wwwwwWwwwWWwwwwwwwwwwwwwwwwwwWWWwwWWWWwwwwww
wwwwwwwwwwwwwwwwwwWWWWWwwWWWWWWwwwwwwwWWWW
WWWwwWWWWWWWWwwwwwwWWWWWWWWWwwWWWWWWWW
WWwwwwwwWWWWWWWWWWWwwwwwwwwwwwwwwwwwwwwwww

Others

External resources

Implementation