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 wwv, the function returns its last argument.

Examples

The following code prints a single 'w'.

wWWwwww

which is equivalent to the following ML-like code:

f0 = read
f1 = @119
f2 = next
f3 = out
f4__main a4 = do
  a5 = f3 f1
  return a5
_ = f4 f4

The following code prints 'w' forever.

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

which is equivalent to the following code:

f0 = read
f1 = @119
f2 = next
f3 = out
f4__main a4__self = do
  a5 = f3 f1
  a6 = a4 a4
  return a6
_ = f4 f4

Said to implement fixed-point combinator:

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

which can be translated to

f4 a4__x a5__v = do
  a6__xx = a4 a4
  a7__xxv = a6 a5
  return a7
f5 a5__f a6__x = do
  a7__\v.xxv = f4 a6
  a8__f(\v.xxv) = a5 a7
  return a8
f6 a6__f = do
  a7__\x.f(\v.xxv) = f5 a6
  a8 = a7 a7
  return a8

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:

f4__1 a4__f a5__x = do
  a6 = a4 a5
  return a6
f5__(+) a5__m a6__n a7__f a8__x = do
  a9__nf = a6 a7
  a10__nfx = a9 a8
  a11__mf = a5 a7
  a12__mf(nfx) = a11 a10
  return a12
f6__main a6 = do
  a7__(1+) = f5 f4
  a8__(1+)1 = a7 f4
  a9__2out = a8 f3
  a10__2out@119 = a9 f1
  return a10
_ = f6 f6

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

See also