# gecho

The **gecho** programming language is often referred to without a capital 'g', and was created by Max Bernstein ( User:Tekknolagi ) in summer of 2011.

## Contents

## Inspiration

This language was inspired by FORTH. It is stack-based.

## Naming

This language was named after a typo by the author. He "meant to type 'echo' but wrote a 'g' in front by accident."

## Commands

**NOTE:** gecho **does not** by default display the result of the operation! One **must** use `.`

- +
Pops two elements from the stack, adds them together, and pushes the result.

- ++
Pops all the elements from the stack and adds them together; pushes result.

- .
Prints the top element in the stack.

- *
Pops two elements from the stack, multiplies them, and pushes the result.

- dels
Pops all elements from the stack.

- show
Pretty prints the stack.

- dup
Pushes a copy of the top element of the stack.

- swap
Pops two elements from the stack, and pushes back in each other's places.

- -
Pops two elements from the stack, subtracts the upper from the lower, and pushes the result.

- jump
Pops an element from the stack (a) and prints stack[a]

- range
Pops two elements from the stack (a, b) and prints range(b, a); starts at b, increments by one until a, pushes the array onto the stack.

- [num]
Pushes `num` to the stack.

- **
Pops all the elements from the stack and multiplies them; pushes result.

- ![tapeindex]
Pop element from stack; set variables[tapeindex] to popped value.

- &[tapeindex]
Push variables[tapeindex] to the stack.

- wover
a = pop(); b = pop(); push(b); push(a); push(b); ( a1 a2 -- a1 a2 a1)

- drop
Pop top element from stack, show value.

- pop
see `drop`

- top
Push the index of the top of the stack to the stack.

- outascii
Pop top element of stack and print ASCII character that corresponds to decimal.

- print
Pop all elements of stack and prints ASCII characters that correspond to decimal.

- /
Pop top two elements from stack; divide lower element by upper element.

- @[mode]
Toggles mode specified.

- mode
Prints a list of all enabled modes.

- modes
Prints all modes, complete with 'enabled' flag.

- tot
For use with @tracker. Prints number of commands so far. Does not count as a command.

- reset
Resets the command count. For use with @tracker. Does not count as a command.

- tan
Pops one element from the stack (degrees!) computes tan(x)

- sin
Pops one element from the stack and computes sin(x)

- cos
Pops one element from the stack and computes cos(x)

- pow
a = pop(); b = pop(); push(b^a);

- mod
a = pop(); b = pop(); push(b%a);

- read
Reads user input. Only really useful with file reading/compiling. Pops one element from the stack and reads that number of numbers, and pushes them to the stack.

- <
b = pop(); a = pop(); push(a < b);

- >
a > b

- >=
a >= b

- <=
a <= b

- =
a == b

- '[word]
Push each character of <word> onto the stack.

- <>
Push ' ' to the stack.

- and
Push a && b to the stack.

- or
Push a || b to the stack.

- nil
Does absolutely nothing.

- next
Cycles through the stacks. If on stack 1, will move to stack 2.

- back
Does the opposite of `next`.

- mv
Moves the top element from the current stack to the next stack. To COPY, use `dup mv`.

## Turing completeness

It is not yet Turing complete.

## Examples

### Hello World

'Hello, <> 'world! print

### Limited Fibonacci

0 1 dup wover + dup wover + dup wover + dup wover +

### Factorial

5 1 range **

Pushes the numbers 1 through 5 onto the stack, and then multiplies them all.

### Multiple Stacks

1 2 + show next 3 4 + show

Computes 1+2, shows it, moves to the next stack, computes 3+4, and shows it.

See `mv` on how to exchange information between stacks.

## Future Syntax

### Loops

5 0 [ i ]

This pushes 5 and 0 to the stack, and then iterates from 0 to 5. `i` pushes the counter to the data stack each iteration. Fibonacci in a loop:

0 1 10 0 [ dup wover + ]

Iterates from 1 to ten, calculating 10 fibonacci numbers.

### If Statements

if { 2 3 < ; 1 + ; 1 - }

If `2<3`, it adds one to the top of the stack. Otherwise, it subtracts one.

### Function definitions

@sayhi { 'hello <> 'world print }

Stores the body into the function `sayhi` and whenever `*sayhi` is seen, it calls `sayhi`. Uses the stack for arguments.

@add { + }

Takes two arguments from the stack, adds them, and pushes the result.

## Implementations

### Downloadable

Its original implementation (and current implementation) can be found at [1].

### Online Interpreter

One can experiment with gecho in an online interpreter at [2].